home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 1 / Atari Mega Archive - Volume 1.iso / gnu / gas / gassrc02.zoo / m68k.c < prev    next >
C/C++ Source or Header  |  1992-04-27  |  85KB  |  3,803 lines

  1. /*
  2.  * HISTORY
  3.  * 09-Sep-91  Shin Iwamoto (shin) at CANON Inc.
  4.  *    Changed the default machine type as mc68040.
  5.  *    Only changed the initial value of m68k_kind.
  6.  * 09-Aug-91  Shin Iwamoto (shin) at CANON Inc.
  7.  *    Supported -m68040 option. When -m68040 is specified,
  8.  *    indirectly supported floating-point instructions and
  9.  *    68020 instructions (callm and rtm) aren't assembled.
  10.  * 31-Jul-91  Shin Iwamoto (shin) at CANON Inc.
  11.  *    Changed <caches> definitions for CINV as mnemonic.
  12.  * 23-Jan-91  K. Chyo (chyo) at DPS of CANON Inc.
  13.  *    Supported instructions on mc68040.
  14.  */
  15.  
  16. /* m68k.c  All the m68020 specific stuff in one convenient, huge,
  17.    slow to compile, easy to find file.
  18.    Copyright (C) 1987 Free Software Foundation, Inc.
  19.  
  20. This file is part of GAS, the GNU Assembler.
  21.  
  22. GAS is free software; you can redistribute it and/or modify
  23. it under the terms of the GNU General Public License as published by
  24. the Free Software Foundation; either version 1, or (at your option)
  25. any later version.
  26.  
  27. GAS is distributed in the hope that it will be useful,
  28. but WITHOUT ANY WARRANTY; without even the implied warranty of
  29. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  30. GNU General Public License for more details.
  31.  
  32. You should have received a copy of the GNU General Public License
  33. along with GAS; see the file COPYING.  If not, write to
  34. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  35.  
  36. #include <ctype.h>
  37.  
  38. #include "m68k-opcode.h"
  39. #include "as.h"
  40. #include "obstack.h"
  41. #include "frags.h"
  42. #include "struc-symbol.h"
  43. #include "flonum.h"
  44. #include "expr.h"
  45. #include "hash.h"
  46. #include "md.h"
  47. #include "m68k.h"
  48.  
  49. #ifdef M_SUN
  50. /* This variable contains the value to write out at the beginning of
  51.    the a.out file.  The 2<<16 means that this is a 68020 file instead
  52.    of an old-style 68000 file */
  53.  
  54. long omagic = 2<<16|OMAGIC;    /* Magic byte for header file */
  55. #else
  56. long omagic = OMAGIC;
  57. #endif
  58.  
  59.  
  60. /* This array holds the chars that always start a comment.  If the
  61.    pre-processor is disabled, these aren't very useful */
  62. const char comment_chars[] = "|";
  63.  
  64. /* This array holds the chars that only start a comment at the beginning of
  65.    a line.  If the line seems to have the form '# 123 filename'
  66.    .line and .file directives will appear in the pre-processed output */
  67. /* Note that input_file.c hand checks for '#' at the beginning of the
  68.    first line of the input file.  This is because the compiler outputs
  69.    #NO_APP at the beginning of its output. */
  70. /* Also note that '/*' will always start a comment */
  71. const char line_comment_chars[] = "#";
  72.  
  73. /* Chars that can be used to separate mant from exp in floating point nums */
  74. const char EXP_CHARS[] = "eE";
  75.  
  76. /* Chars that mean this number is a floating point constant */
  77. /* As in 0f12.456 */
  78. /* or    0d1.2345e12 */
  79.  
  80. const char FLT_CHARS[] = "rRsSfFdDxXeEpP";
  81.  
  82. /* Also be aware that MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT may have to be
  83.    changed in read.c .  Ideally it shouldn't have to know about it at all,
  84.    but nothing is ideal around here.
  85.  */
  86.  
  87. void fix_new();
  88. void install_operand();
  89. void install_gen_operand();
  90.  
  91. /* Its an arbitrary name:  This means I don't approve of it */
  92. /* See flames below */
  93. struct obstack robyn;
  94.  
  95. #define TAB(x,y)    (((x)<<2)+(y))
  96. #define TABTYPE(xy)     ((xy) >> 2)
  97. #define BYTE        0
  98. #define SHORT        1
  99. #define LONG        2
  100. #define SZ_UNDEF    3
  101.  
  102. #define BRANCH        1
  103. #define FBRANCH        2
  104. #define PCREL        3
  105. #define BCC68000        4
  106. #define DBCC            5
  107. #define PCLEA        6
  108.  
  109. /* BCC68000 is for patching in an extra jmp instruction for long offsets
  110.    on the 68000.  The 68000 doesn't support long branches with branchs */
  111.  
  112. /* This table desribes how you change sizes for the various types of variable
  113.    size expressions.  This version only supports two kinds. */
  114.  
  115. /* Note that calls to frag_var need to specify the maximum expansion needed */
  116. /* This is currently 10 bytes for DBCC */
  117.  
  118. /* The fields are:
  119.     How far Forward this mode will reach:
  120.     How far Backward this mode will reach:
  121.     How many bytes this mode will add to the size of the frag
  122.     Which mode to go to if the offset won't fit in this one
  123.  */
  124. const relax_typeS
  125. md_relax_table[] = {
  126. { 1,        1,        0,    0 },    /* First entries aren't used */
  127. { 1,        1,        0,    0 },    /* For no good reason except */
  128. { 1,        1,        0,    0 },    /* that the VAX doesn't either */
  129. { 1,        1,        0,    0 },
  130.  
  131. { (127),    (-128),        0,    TAB(BRANCH,SHORT)},
  132. { (32767),    (-32768),    2,    TAB(BRANCH,LONG) },
  133. { 0,        0,        4,    0 },
  134. { 1,        1,        0,    0 },
  135.  
  136. { 1,        1,        0,    0 },    /* FBRANCH doesn't come BYTE */
  137. { (32767),    (-32768),    2,    TAB(FBRANCH,LONG)},
  138. { 0,        0,        4,    0 },
  139. { 1,        1,        0,    0 },
  140.  
  141. { 1,        1,        0,    0 },    /* PCREL doesn't come BYTE */
  142. { (32767),    (-32768),    2,    TAB(PCREL,LONG)},
  143. { 0,        0,        4,    0 },
  144. { 1,        1,        0,    0 },
  145.  
  146. { (127),    (-128),        0,    TAB(BCC68000,SHORT)},
  147. { (32767),    (-32768),    2,    TAB(BCC68000,LONG) },
  148. { 0,        0,        6,    0 },    /* jmp long space */
  149. { 1,        1,        0,    0 },
  150.  
  151. { 1,        1,        0,    0 },    /* DBCC doesn't come BYTE */
  152. { (32767),    (-32768),    2,    TAB(DBCC,LONG) },
  153. { 0,        0,        10,    0 },    /* bra/jmp long space */
  154. { 1,        1,        0,    0 },
  155.  
  156. { 1,        1,        0,    0 },    /* PCLEA doesn't come BYTE */
  157. { 32767,    -32768,        2,    TAB(PCLEA,LONG) },
  158. { 0,        0,        6,    0 },
  159. { 1,        1,        0,    0 },
  160.  
  161. };
  162.  
  163. void    s_data1(),    s_data2(),    s_even(),    s_space();
  164. void    s_proc(),    float_cons();
  165.  
  166. /* These are the machine dependent pseudo-ops.  These are included so
  167.    the assembler can work on the output from the SUN C compiler, which
  168.    generates these.
  169.  */
  170.  
  171. /* This table describes all the machine specific pseudo-ops the assembler
  172.    has to support.  The fields are:
  173.        pseudo-op name without dot
  174.       function to call to execute this pseudo-op
  175.       Integer arg to pass to the function
  176.  */
  177. const pseudo_typeS md_pseudo_table[] = {
  178.     { "data1",    s_data1,    0    },
  179.     { "data2",    s_data2,    0    },
  180.     { "even",    s_even,        0    },
  181.     { "skip",    s_space,    0    },
  182.     { "proc",    s_proc,        0    },
  183.     { 0,        0,        0    }
  184. };
  185.  
  186.  
  187. /* #define isbyte(x)    ((x)>=-128 && (x)<=127) */
  188. /* #define isword(x)    ((x)>=-32768 && (x)<=32767) */
  189.  
  190. #define issbyte(x)    ((x)>=-128 && (x)<=127)
  191. #define isubyte(x)    ((x)>=0 && (x)<=255)
  192. #define issword(x)    ((x)>=-32768 && (x)<=32767)
  193. #define isuword(x)    ((x)>=0 && (x)<=65535)
  194.  
  195. #define isbyte(x)    ((x)>=-128 && (x)<=255)
  196. #define isword(x)    ((x)>=-32768 && (x)<=65535)
  197. #define islong(x)    (1)
  198.  
  199. extern char *input_line_pointer;
  200.  
  201. /* Operands we can parse:  (And associated modes)
  202.  
  203. numb:    8 bit num
  204. numw:    16 bit num
  205. numl:    32 bit num
  206. dreg:    data reg 0-7
  207. reg:    address or data register
  208. areg:    address register
  209. apc:    address register, PC, ZPC or empty string
  210. num:    16 or 32 bit num
  211. num2:    like num
  212. sz:    w or l        if omitted, l assumed
  213. scale:    1 2 4 or 8    if omitted, 1 assumed
  214.  
  215. 7.4 IMMED #num                --> NUM
  216. 0.? DREG  dreg                --> dreg
  217. 1.? AREG  areg                --> areg
  218. 2.? AINDR areg@                --> *(areg)
  219. 3.? AINC  areg@+            --> *(areg++)
  220. 4.? ADEC  areg@-            --> *(--areg)
  221. 5.? AOFF  apc@(numw)            --> *(apc+numw)    -- empty string and ZPC not allowed here
  222. 6.? AINDX apc@(num,reg:sz:scale)    --> *(apc+num+reg*scale)
  223. 6.? AINDX apc@(reg:sz:scale)        --> same, with num=0
  224. 6.? APODX apc@(num)@(num2,reg:sz:scale)    --> *(*(apc+num)+num2+reg*scale)
  225. 6.? APODX apc@(num)@(reg:sz:scale)    --> same, with num2=0
  226. 6.? AMIND apc@(num)@(num2)        --> *(*(apc+num)+num2) (previous mode without an index reg)
  227. 6.? APRDX apc@(num,reg:sz:scale)@(num2)    --> *(*(apc+num+reg*scale)+num2)
  228. 6.? APRDX apc@(reg:sz:scale)@(num2)    --> same, with num=0
  229. 7.0 ABSL  num:sz            --> *(num)
  230.           num                --> *(num) (sz L assumed)
  231. *** MSCR  otherreg            --> Magic
  232. With -l option
  233. 5.? AOFF  apc@(num)            --> *(apc+num) -- empty string and ZPC not allowed here still
  234.  
  235. examples:
  236.     #foo    #0x35    #12
  237.     d2
  238.     a4
  239.     a3@
  240.     a5@+
  241.     a6@-
  242.     a2@(12)    pc@(14)
  243.     a1@(5,d2:w:1)    @(45,d6:l:4)
  244.     pc@(a2)        @(d4)
  245.     etc . . .
  246.  
  247.  
  248. #name@(numw)    -->turn into PC rel mode
  249. apc@(num8,reg:sz:scale)        --> *(apc+num8+reg*scale)
  250.  
  251. */
  252.  
  253. #define IMMED    1
  254. #define DREG    2
  255. #define AREG    3
  256. #define AINDR    4
  257. #define ADEC    5
  258. #define AINC    6
  259. #define AOFF    7
  260. #define AINDX    8
  261. #define APODX    9
  262. #define AMIND    10
  263. #define APRDX    11
  264. #define ABSL    12
  265. #define MSCR    13
  266. #define REGLST    14
  267.  
  268. #define FAIL    0
  269. #define OK    1
  270.  
  271. /* DATA and ADDR have to be contiguous, so that reg-DATA gives 0-7==data reg,
  272.    8-15==addr reg for operands that take both types */
  273. #define DATA    1        /*   1- 8 == data registers 0-7 */
  274. #define ADDR    (DATA+8)    /*   9-16 == address regs 0-7 */
  275. #define FPREG    (ADDR+8)    /*  17-24 Eight FP registers */
  276. #define COPNUM    (FPREG+8)    /*  25-32 Co-processor #1-#8 */
  277.  
  278. #define PC    (COPNUM+8)    /*  33 Program counter */
  279. #define ZPC    (PC+1)        /*  34 Hack for Program space, but 0 addressing */
  280. #define SR    (ZPC+1)        /*  35 Status Reg */
  281. #define CCR    (SR+1)        /*  36 Condition code Reg */
  282.  
  283. /* These have to be in order for the movec instruction to work. */
  284. #define USP    (CCR+1)        /*  37 User Stack Pointer */
  285. #define ISP    (USP+1)        /*  38 Interrupt stack pointer */
  286. #define SFC    (ISP+1)        /*  39 */
  287. #define DFC    (SFC+1)        /*  40 */
  288. #define CACR    (DFC+1)        /*  41 */
  289. #define VBR    (CACR+1)    /*  42 */
  290. #define CAAR    (VBR+1)        /*  43 */
  291. #define MSP    (CAAR+1)    /*  44 */
  292.  
  293. #define FPI    (MSP+1)        /* 45 */
  294. #define FPS    (FPI+1)        /* 46 */
  295. #define FPC    (FPS+1)        /* 47 */
  296.  
  297. #ifdef m68040
  298. #define TC    (FPC+1)        /* 48 */
  299. #define ITT0    (TC+1)        /* 49 */
  300. #define ITT1    (ITT0+1)    /* 50 */
  301. #define DTT0    (ITT1+1)    /* 51 */
  302. #define DTT1    (DTT0+1)    /* 52 */
  303. #define MMUSR    (DTT1+1)    /* 53 */
  304. #define URP    (MMUSR+1)    /* 54 */
  305. #define SRP    (URP+1)        /* 55 */
  306.  
  307. #define    NC    (SRP+1)        /* 56 */
  308. #define    DC    (NC+1)        /* 57 */
  309. #define    IC    (NC+2)        /* 58 */
  310. #define    BC    (NC+3)        /* 59 */
  311.  
  312. #else /* m68040 */
  313. /*
  314.  * these defines should be in m68k.c but
  315.  * i put them here to keep all the m68851 stuff
  316.  * together -rab
  317.  * JF--Make sure these #s don't clash with the ones in m68k.c
  318.  * That would be BAD.
  319.  */
  320. #define TC    (FPC+1)        /* 48 */
  321. #define DRP    (TC+1)        /* 49 */
  322. #define SRP    (DRP+1)        /* 50 */
  323. #define CRP    (SRP+1)        /* 51 */
  324. #define CAL    (CRP+1)        /* 52 */
  325. #define VAL    (CAL+1)        /* 53 */
  326. #define SCC    (VAL+1)        /* 54 */
  327. #define AC    (SCC+1)        /* 55 */
  328. #define BAD    (AC+1)        /* 56,57,58,59, 60,61,62,63 */
  329. #define BAC    (BAD+8)        /* 64,65,66,67, 68,69,70,71 */
  330. #define PSR    (BAC+8)        /* 72 */
  331. #define PCSR    (PSR+1)        /* 73 */
  332. #endif m68040
  333.  
  334.  
  335. /* Note that COPNUM==processor #1 -- COPNUM+7==#8, which stores as 000 */
  336. /* I think. . .  */
  337.  
  338. #define    SP    ADDR+7
  339.  
  340. /* JF these tables here are for speed at the expense of size */
  341. /* You can replace them with the #if 0 versions if you really
  342.    need space and don't mind it running a bit slower */
  343.  
  344. static char mklower_table[256];
  345. #define mklower(c) (mklower_table[(unsigned char)(c)])
  346. static char notend_table[256];
  347. static char alt_notend_table[256];
  348. #define notend(s) ( !(notend_table[(unsigned char)(*s)] || (*s==':' &&\
  349.  alt_notend_table[(unsigned char)(s[1])])))
  350.  
  351. #if 0
  352. #define mklower(c)    (isupper(c) ? tolower(c) : c)
  353. #endif
  354.  
  355.  
  356. struct m68k_exp {
  357.     char    *e_beg;
  358.     char    *e_end;
  359.     expressionS e_exp;
  360.     short    e_siz;        /* 0== default 1==short/byte 2==word 3==long */
  361. };
  362.  
  363. /* Internal form of an operand.  */
  364. struct m68k_op {
  365.     char    *error;        /* Couldn't parse it */
  366.     int    mode;        /* What mode this instruction is in.  */
  367.     unsigned long int    reg;        /* Base register */
  368.     struct m68k_exp *con1;
  369.     int    ireg;        /* Index register */
  370.     int    isiz;        /* 0==unspec  1==byte(?)  2==short  3==long  */
  371.     int    imul;        /* Multipy ireg by this (1,2,4,or 8) */
  372.     struct    m68k_exp *con2;
  373. };
  374.  
  375. /* internal form of a 68020 instruction */
  376. struct m68_it {
  377.     char    *error;
  378.     char    *args;        /* list of opcode info */
  379.     int    numargs;
  380.  
  381.     int    numo;        /* Number of shorts in opcode */
  382.     short    opcode[11];
  383.  
  384.     struct m68k_op operands[6];
  385.  
  386.     int    nexp;        /* number of exprs in use */
  387.     struct m68k_exp exprs[4];
  388.  
  389.     int    nfrag;        /* Number of frags we have to produce */
  390.     struct {
  391.         int fragoff;    /* Where in the current opcode[] the frag ends */
  392.         symbolS *fadd;
  393.         long int foff;
  394.         int fragty;
  395.     } fragb[4];
  396.  
  397.     int    nrel;        /* Num of reloc strucs in use */
  398.     struct    {
  399.         int    n;
  400.         symbolS    *add,
  401.             *sub;
  402.         long int off;
  403.         char    wid;
  404.         char    pcrel;
  405.     } reloc[5];        /* Five is enough??? */
  406. };
  407.  
  408. struct m68_it the_ins;        /* the instruction being assembled */
  409.  
  410.  
  411. /* Macros for adding things to the m68_it struct */
  412.  
  413. #define addword(w)    the_ins.opcode[the_ins.numo++]=(w)
  414.  
  415. /* Like addword, but goes BEFORE general operands */
  416. #define insop(w)    {int z;\
  417.  for(z=the_ins.numo;z>opcode->m_codenum;--z)\
  418.    the_ins.opcode[z]=the_ins.opcode[z-1];\
  419.  for(z=0;z<the_ins.nrel;z++)\
  420.    the_ins.reloc[z].n+=2;\
  421.  the_ins.opcode[opcode->m_codenum]=w;\
  422.  the_ins.numo++;\
  423. }
  424.  
  425.  
  426. #define add_exp(beg,end) (\
  427.     the_ins.exprs[the_ins.nexp].e_beg=beg,\
  428.     the_ins.exprs[the_ins.nexp].e_end=end,\
  429.     &the_ins.exprs[the_ins.nexp++]\
  430. )
  431.  
  432.  
  433. /* The numo+1 kludge is so we can hit the low order byte of the prev word. Blecch*/
  434. #define add_fix(width,exp,pc_rel) {\
  435.     the_ins.reloc[the_ins.nrel].n= ((width)=='B') ? (the_ins.numo*2-1) : \
  436.         (((width)=='b') ? ((the_ins.numo-1)*2) : (the_ins.numo*2));\
  437.     the_ins.reloc[the_ins.nrel].add=adds((exp));\
  438.     the_ins.reloc[the_ins.nrel].sub=subs((exp));\
  439.     the_ins.reloc[the_ins.nrel].off=offs((exp));\
  440.     the_ins.reloc[the_ins.nrel].wid=width;\
  441.     the_ins.reloc[the_ins.nrel++].pcrel=pc_rel;\
  442. }
  443.  
  444. #define add_frag(add,off,type)  {\
  445.     the_ins.fragb[the_ins.nfrag].fragoff=the_ins.numo;\
  446.     the_ins.fragb[the_ins.nfrag].fadd=add;\
  447.     the_ins.fragb[the_ins.nfrag].foff=off;\
  448.     the_ins.fragb[the_ins.nfrag++].fragty=type;\
  449. }
  450.  
  451. #define isvar(exp)    ((exp) && (adds(exp) || subs(exp)))
  452.  
  453. #define seg(exp)    ((exp)->e_exp.X_seg)
  454. #define adds(exp)    ((exp)->e_exp.X_add_symbol)
  455. #define subs(exp)    ((exp)->e_exp.X_subtract_symbol)
  456. #define offs(exp)    ((exp)->e_exp.X_add_number)
  457.  
  458.  
  459. struct m68_incant {
  460.     char *m_operands;
  461.     unsigned long m_opcode;
  462.     short m_opnum;
  463.     short m_codenum;
  464.     struct m68_incant *m_next;
  465. };
  466.  
  467. #define getone(x)    ((((x)->m_opcode)>>16)&0xffff)
  468. #define gettwo(x)    (((x)->m_opcode)&0xffff)
  469.  
  470. #ifdef m68040
  471. /*
  472.  * When m68k_kind is 4 (meaning m68040), our as doesn't assemble indirectly
  473.  * supported floating-point instructions. And then the default is 4.
  474.  */
  475. /* int    m68k_kind = 4; *
  476.  
  477. /* ++jrb -- change m68k_kind to 0, to use 68040 support use -m68040 arg */
  478. int    m68k_kind = 4;
  479. #endif m68040
  480.  
  481. /* JF modified this to handle cases where the first part of a symbol name
  482.    looks like a register */
  483.  
  484. int
  485. m68k_reg_parse(ccp)
  486. register char **ccp;
  487. {
  488.     register char c1,
  489.         c2,
  490.         c3,
  491. #ifdef m68040
  492.         c4,
  493.         c5;
  494. #else
  495.         c4;
  496. #endif m68040
  497.     register int n = 0,
  498.         ret = FAIL;
  499.  
  500.     c1=mklower(ccp[0][0]);
  501. #ifdef REGISTER_PREFIX
  502.     if(c1!=REGISTER_PREFIX)
  503.         return FAIL;
  504.     c1=mklower(ccp[0][1]);
  505.     c2=mklower(ccp[0][2]);
  506.     c3=mklower(ccp[0][3]);
  507.     c4=mklower(ccp[0][4]);
  508. #ifdef m68040
  509.     c5=mklower(ccp[0][5]);
  510. #endif m68040
  511. #else
  512.     c2=mklower(ccp[0][1]);
  513.     c3=mklower(ccp[0][2]);
  514.     c4=mklower(ccp[0][3]);
  515. #ifdef m68040
  516.     c5=mklower(ccp[0][4]);
  517. #endif m68040
  518. #endif
  519.     switch(c1) {
  520.     case 'a':
  521.         if(c2>='0' && c2<='7') {
  522.             n=2;
  523.             ret=ADDR+c2-'0';
  524.         }
  525. #ifdef m68851
  526.         else if (c2 == 'c') {
  527.             n = 2;
  528.             ret = AC;
  529.         }
  530. #endif
  531.         break;
  532. #ifdef m68040
  533.     case 'b':
  534.         if (c2 == 'c') {
  535.             n = 2;
  536.             ret = BC;
  537.         }
  538.         break;
  539. #endif m68040
  540. #ifdef m68851
  541.     case 'b':
  542.         if (c2 == 'a') {
  543.             if (c3 == 'd') {
  544.                 if (c4 >= '0' && c4 <= '7') {
  545.                     n = 4;
  546.                     ret = BAD + c4 - '0';
  547.                 }
  548.             }
  549.             if (c3 == 'c') {
  550.                 if (c4 >= '0' && c4 <= '7') {
  551.                     n = 4;
  552.                     ret = BAC + c4 - '0';
  553.                 }
  554.             }
  555.         }
  556.         break;
  557. #endif
  558.     case 'c':
  559. #ifdef m68851
  560.         if (c2 == 'a' && c3 == 'l') {
  561.             n = 3;
  562.             ret = CAL;
  563.         } else
  564. #endif
  565.             /* This supports both CCR and CC as the ccr reg. */
  566.         if(c2=='c' && c3=='r') {
  567.             n=3;
  568.             ret = CCR;
  569.         } else if(c2=='c') {
  570.             n=2;
  571.             ret = CCR;
  572.         } else if(c2=='a' && (c3=='a' || c3=='c') && c4=='r') {
  573.             n=4;
  574.             ret = c3=='a' ? CAAR : CACR;
  575.         }
  576. #ifdef m68851
  577.         else if (c2 == 'r' && c3 == 'p') {
  578.             n = 3;
  579.             ret = (CRP);
  580.         }
  581. #endif
  582.         break;
  583.     case 'd':
  584.         if(c2>='0' && c2<='7') {
  585.             n=2;
  586.             ret = DATA+c2-'0';
  587.         } else if(c2=='f' && c3=='c') {
  588.             n=3;
  589.             ret = DFC;
  590.         }
  591. #ifdef m68851
  592.         else if (c2 == 'r' && c3 == 'p') {
  593.             n = 3;
  594.             ret = (DRP);
  595.         }
  596. #endif
  597. #ifdef m68040
  598.         else if (c2 == 't' && c3 == 't' && c4 == '0') {
  599.              n = 4;
  600.             ret = DTT0;
  601.         }
  602.         else if (c2 == 't' && c3 == 't' && c4 == '1') {
  603.             n = 4;
  604.             ret = DTT1;
  605.         }
  606.         else if (c2 == 'c') {
  607.             n = 2;
  608.             ret = DC;
  609.         }
  610. #endif m68040
  611.         break;
  612.     case 'f':
  613.         if(c2=='p') {
  614.             if(c3>='0' && c3<='7') {
  615.                 n=3;
  616.                 ret = FPREG+c3-'0';
  617.                 if(c4==':')
  618.                     ccp[0][3]=',';
  619.             } else if(c3=='i') {
  620.                 n=3;
  621.                 ret = FPI;
  622.             } else if(c3=='s') {
  623.                 n= (c4 == 'r' ? 4 : 3);
  624.                 ret = FPS;
  625.             } else if(c3=='c') {
  626.                 n= (c4 == 'r' ? 4 : 3);
  627.                 ret = FPC;
  628.             }
  629.         }
  630.         break;
  631.     case 'i':
  632.         if(c2=='s' && c3=='p') {
  633.             n=3;
  634.             ret = ISP;
  635.         }
  636. #ifdef m68040
  637.         else if (c2 == 't' && c3 == 't' && c4 == '0') {
  638.             n = 4;
  639.             ret = ITT0;
  640.         }
  641.         else if (c2 == 't' && c3 == 't' && c4 == '1') {
  642.             n = 4;
  643.             ret = ITT1;
  644.         }
  645.         else if (c2 == 'c') { 
  646.             n = 2;
  647.             ret = IC;
  648.         }
  649. #endif m68040
  650.         break;
  651.     case 'm':
  652.         if(c2=='s' && c3=='p') {
  653.             n=3;
  654.             ret = MSP;
  655.         }
  656. #ifdef m68040
  657.         else if (c2 == 'm' && c3 == 'u' && c4 == 's' && c5 == 'r') 
  658.         {
  659.             n = 5;
  660.             ret = MMUSR;
  661.         }
  662. #endif m68040
  663.         break;
  664. #ifdef m68040
  665.     case 'n':
  666.         if(c2=='c') {
  667.             n=2;
  668.             ret = NC;
  669.         }
  670.         break;
  671. #endif m68040
  672.     case 'p':
  673.         if(c2=='c') {
  674. #ifdef m68851
  675.             if(c3 == 's' && c4=='r') {
  676.                 n=4;
  677.                 ret = (PCSR);
  678.             } else
  679. #endif
  680.             {
  681.                 n=2;
  682.                 ret = PC;
  683.             }
  684.         }
  685. #ifdef m68851
  686.         else if (c2 == 's' && c3 == 'r') {
  687.             n = 3;
  688.             ret = (PSR);
  689.         }
  690. #endif
  691.         break;
  692.     case 's':
  693. #ifdef m68040
  694.         if (c2 == 'r' && c3 == 'p') {
  695.             n = 3;
  696.             ret = (SRP);
  697.         } else
  698. #endif m68040
  699. #ifdef m68851
  700.         if (c2 == 'c' && c3 == 'c') {
  701.             n = 3;
  702.             ret = (SCC);
  703.         } else if (c2 == 'r' && c3 == 'p') {
  704.             n = 3;
  705.             ret = (SRP);
  706.         } else
  707. #endif
  708.         if(c2=='r') {
  709.             n=2;
  710.             ret = SR;
  711.         } else if(c2=='p') {
  712.             n=2;
  713.             ret = ADDR+7;
  714.         } else if(c2=='f' && c3=='c') {
  715.             n=3;
  716.             ret = SFC;
  717.         }
  718.         break;
  719. #if defined(m68851) || defined(m68040)
  720.     case 't':
  721.         if(c2 == 'c') {
  722.             n=2;
  723.             ret=TC;
  724.         }
  725.         break;
  726. #endif
  727.     case 'u':
  728. #ifdef m68040
  729.         if (c2 == 'r' && c3 == 'p') {
  730.             n = 3;
  731.             ret = (URP);
  732.         } else
  733. #endif m68040
  734.         if(c2=='s' && c3=='p') {
  735.             n=3;
  736.             ret = USP;
  737.         }
  738.         break;
  739.     case 'v':
  740. #ifdef m68851
  741.         if (c2 == 'a' && c3 == 'l') {
  742.             n = 3;
  743.             ret = (VAL);
  744.         } else
  745. #endif
  746.         if(c2=='b' && c3=='r') {
  747.             n=3;
  748.             ret = VBR;
  749.         }
  750.         break;
  751.     case 'z':
  752.         if(c2=='p' && c3=='c') {
  753.             n=3;
  754.             ret = ZPC;
  755.         }
  756.         break;
  757.     default:
  758.         break;
  759.     }
  760.     if(n) {
  761. #ifdef REGISTER_PREFIX
  762.         n++;
  763. #endif
  764.         if(isalnum(ccp[0][n]) || ccp[0][n]=='_')
  765.             ret=FAIL;
  766.         else
  767.             ccp[0]+=n;
  768.     } else
  769.         ret = FAIL;
  770.     return ret;
  771. }
  772.  
  773. #define SKIP_WHITE()    { str++; if(*str==' ') str++;}
  774.  
  775. int
  776. m68k_ip_op(str,opP)
  777. char *str;
  778. register struct m68k_op *opP;
  779. {
  780.     char    *strend;
  781.     long    i;
  782.     char    *parse_index();
  783.  
  784.     if(*str==' ')
  785.         str++;
  786.         /* Find the end of the string */
  787.     if(!*str) {
  788.         /* Out of gas */
  789.         opP->error="Missing operand";
  790.         return FAIL;
  791.     }
  792.     for(strend=str;*strend;strend++)
  793. #if defined(CANON) && defined(SUN_ASM_SYNTAX)
  794.         if (*strend == ' ' || *strend == '\t') {
  795.             *strend = '\0';
  796.             break;
  797.         }
  798. #else
  799.         ;
  800. #endif CANON && SUN_ASM_SYNTAX
  801.     --strend;
  802.  
  803.         /* Guess what:  A constant.  Shar and enjoy */
  804.     if(*str=='#') {
  805.         str++;
  806.         opP->con1=add_exp(str,strend);
  807.         opP->mode=IMMED;
  808.         return OK;
  809.     }
  810.     i=m68k_reg_parse(&str);
  811.     if((i==FAIL || *str!='\0') && *str!='@') {
  812.         char *stmp;
  813.         char *index();
  814.  
  815.         if(i!=FAIL && (*str=='/' || *str=='-')) {
  816.             opP->mode=REGLST;
  817.             return get_regs(i,str,opP);
  818.         }
  819.         if(stmp=index(str,'@')) {
  820.             opP->con1=add_exp(str,stmp-1);
  821.             if(stmp==strend) {
  822.                 opP->mode=AINDX;
  823.                 return OK;
  824.             }
  825.             stmp++;
  826.             if(*stmp++!='(' || *strend--!=')') {
  827.                 opP->error="Malformed operand";
  828.                 return FAIL;
  829.             }
  830.             i=try_index(&stmp,opP);
  831.             opP->con2=add_exp(stmp,strend);
  832.             if(i==FAIL) opP->mode=AMIND;
  833.             else opP->mode=APODX;
  834.             return OK;
  835.         }
  836.         opP->mode=ABSL;
  837.         opP->con1=add_exp(str,strend);
  838.         return OK;
  839.     }
  840.     opP->reg=i;
  841.     if(*str=='\0') {
  842.         if(i>=DATA+0 && i<=DATA+7)
  843.             opP->mode=DREG;
  844.         else if(i>=ADDR+0 && i<=ADDR+7)
  845.             opP->mode=AREG;
  846.         else
  847.             opP->mode=MSCR;
  848.         return OK;
  849.     }
  850.     if((i<ADDR+0 || i>ADDR+7) && i!=PC && i!=ZPC && i!=FAIL) {    /* Can't indirect off non address regs */
  851.         opP->error="Invalid indirect register";
  852.         return FAIL;
  853.     }
  854.     if(*str!='@')
  855.         abort();
  856.     str++;
  857.     switch(*str) {
  858.     case '\0':
  859.         opP->mode=AINDR;
  860.         return OK;
  861.     case '-':
  862.         opP->mode=ADEC;
  863.         return OK;
  864.     case '+':
  865.         opP->mode=AINC;
  866.         return OK;
  867.     case '(':
  868.         str++;
  869.         break;
  870.     default:
  871.         opP->error="Junk after indirect";
  872.         return FAIL;
  873.     }
  874.         /* Some kind of indexing involved.  Lets find out how bad it is */
  875.     i=try_index(&str,opP);
  876.         /* Didn't start with an index reg, maybe its offset or offset,reg */
  877.     if(i==FAIL) {
  878.         char *beg_str;
  879.  
  880.         beg_str=str;
  881.         for(i=1;i;) {
  882.             switch(*str++) {
  883.             case '\0':
  884.                 opP->error="Missing )";
  885.                 return FAIL;
  886.             case ',': i=0; break;
  887.             case '(': i++; break;
  888.             case ')': --i; break;
  889.             }
  890.         }
  891.         /* if(str[-3]==':') {
  892.             int siz;
  893.  
  894.             switch(str[-2]) {
  895.             case 'b':
  896.             case 'B':
  897.                 siz=1;
  898.                 break;
  899.             case 'w':
  900.             case 'W':
  901.                 siz=2;
  902.                 break;
  903.             case 'l':
  904.             case 'L':
  905.                 siz=3;
  906.                 break;
  907.             default:
  908.                 opP->error="Specified size isn't :w or :l";
  909.                 return FAIL;
  910.             }
  911.             opP->con1=add_exp(beg_str,str-4);
  912.             opP->con1->e_siz=siz;
  913.         } else */
  914.             opP->con1=add_exp(beg_str,str-2);
  915.             /* Should be offset,reg */
  916.         if(str[-1]==',') {
  917.             i=try_index(&str,opP);
  918.             if(i==FAIL) {
  919.                 opP->error="Malformed index reg";
  920.                 return FAIL;
  921.             }
  922.         }
  923.     }
  924.         /* We've now got offset)   offset,reg)   or    reg) */
  925.  
  926.     if(*str=='\0') {
  927.         /* Th-the-thats all folks */
  928.         if(opP->reg==FAIL) opP->mode=AINDX;    /* Other form of indirect */
  929.         else if(opP->ireg==FAIL) opP->mode=AOFF;
  930.         else opP->mode=AINDX;
  931.         return OK;
  932.     }
  933.         /* Next thing had better be another @ */
  934.     if(*str!='@' || str[1]!='(') {
  935.         opP->error="junk after indirect";
  936.         return FAIL;
  937.     }
  938.     str+=2;
  939.     if(opP->ireg!=FAIL) {
  940.         opP->mode=APRDX;
  941.         i=try_index(&str,opP);
  942.         if(i!=FAIL) {
  943.             opP->error="Two index registers!  not allowed!";
  944.             return FAIL;
  945.         }
  946.     } else
  947.         i=try_index(&str,opP);
  948.     if(i==FAIL) {
  949.         char *beg_str;
  950.  
  951.         beg_str=str;
  952.         for(i=1;i;) {
  953.             switch(*str++) {
  954.             case '\0':
  955.                 opP->error="Missing )";
  956.                 return FAIL;
  957.             case ',': i=0; break;
  958.             case '(': i++; break;
  959.             case ')': --i; break;
  960.             }
  961.         }
  962.         opP->con2=add_exp(beg_str,str-2);
  963.         if(str[-1]==',') {
  964.             if(opP->ireg!=FAIL) {
  965.                 opP->error="Can't have two index regs";
  966.                 return FAIL;
  967.             }
  968.             i=try_index(&str,opP);
  969.             if(i==FAIL) {
  970.                 opP->error="malformed index reg";
  971.                 return FAIL;
  972.             }
  973.             opP->mode=APODX;
  974.         } else if(opP->ireg!=FAIL)
  975.             opP->mode=APRDX;
  976.         else
  977.             opP->mode=AMIND;
  978.     } else
  979.         opP->mode=APODX;
  980.     if(*str!='\0') {
  981.         opP->error="Junk after indirect";
  982.         return FAIL;
  983.     }
  984.     return OK;
  985. }
  986.  
  987. int
  988. try_index(s,opP)
  989. char **s;
  990. struct m68k_op *opP;
  991. {
  992.     register int    i;
  993.     char    *ss;
  994. #define SKIP_W()    { ss++; if(*ss==' ') ss++;}
  995.  
  996.     ss= *s;
  997.     /* SKIP_W(); */
  998.     i=m68k_reg_parse(&ss);
  999.     if(!(i>=DATA+0 && i<=ADDR+7)) {    /* if i is not DATA or ADDR reg */
  1000.         *s=ss;
  1001.         return FAIL;
  1002.     }
  1003.     opP->ireg=i;
  1004.     /* SKIP_W(); */
  1005.     if(*ss==')') {
  1006.         opP->isiz=0;
  1007.         opP->imul=1;
  1008.         SKIP_W();
  1009.         *s=ss;
  1010.         return OK;
  1011.     }
  1012.     if(*ss!=':') {
  1013.         opP->error="Missing : in index register";
  1014.         *s=ss;
  1015.         return FAIL;
  1016.     }
  1017.     SKIP_W();
  1018.     switch(*ss) {
  1019.     case 'w':
  1020.     case 'W':
  1021.         opP->isiz=2;
  1022.         break;
  1023.     case 'l':
  1024.     case 'L':
  1025.         opP->isiz=3;
  1026.         break;
  1027.     default:
  1028.         opP->error="Index register size spec not :w or :l";
  1029.         *s=ss;
  1030.         return FAIL;
  1031.     }
  1032.     SKIP_W();
  1033.     if(*ss==':') {
  1034.         SKIP_W();
  1035.         switch(*ss) {
  1036.         case '1':
  1037.         case '2':
  1038.         case '4':
  1039.         case '8':
  1040.             opP->imul= *ss-'0';
  1041.             break;
  1042.         default:
  1043.             opP->error="index multiplier not 1, 2, 4 or 8";
  1044.             *s=ss;
  1045.             return FAIL;
  1046.         }
  1047.         SKIP_W();
  1048.     } else opP->imul=1;
  1049.     if(*ss!=')') {
  1050.         opP->error="Missing )";
  1051.         *s=ss;
  1052.         return FAIL;
  1053.     }
  1054.     SKIP_W();
  1055.     *s=ss;
  1056.     return OK;
  1057. }
  1058.  
  1059. #ifdef TEST1    /* TEST1 tests m68k_ip_op(), which parses operands */
  1060. main()
  1061. {
  1062.     char buf[128];
  1063.     struct m68k_op thark;
  1064.  
  1065.     for(;;) {
  1066.         if(!gets(buf))
  1067.             break;
  1068.         bzero(&thark,sizeof(thark));
  1069.         if(!m68k_ip_op(buf,&thark)) printf("FAIL:");
  1070.         if(thark.error)
  1071.             printf("op1 error %s in %s\n",thark.error,buf);
  1072.         printf("mode %d, reg %d, ",thark.mode,thark.reg);
  1073.         if(thark.b_const)
  1074.             printf("Constant: '%.*s',",1+thark.e_const-thark.b_const,thark.b_const);
  1075.         printf("ireg %d, isiz %d, imul %d ",thark.ireg,thark.isiz,thark.imul);
  1076.         if(thark.b_iadd)
  1077.             printf("Iadd: '%.*s'",1+thark.e_iadd-thark.b_iadd,thark.b_iadd);
  1078.         printf("\n");
  1079.     }
  1080.     exit(0);
  1081. }
  1082.  
  1083. #endif
  1084.  
  1085.  
  1086. static struct hash_control*   op_hash = NULL;    /* handle of the OPCODE hash table
  1087.                    NULL means any use before m68_ip_begin()
  1088.                    will crash */
  1089.  
  1090.  
  1091. /*
  1092.  *        m 6 8 _ i p ( )
  1093.  *
  1094.  * This converts a string into a 68k instruction.
  1095.  * The string must be a bare single instruction in sun format
  1096.  * with RMS-style 68020 indirects
  1097.  *  (example:  )
  1098.  *
  1099.  * It provides some error messages: at most one fatal error message (which
  1100.  * stops the scan) and at most one warning message for each operand.
  1101.  * The 68k instruction is returned in exploded form, since we have no
  1102.  * knowledge of how you parse (or evaluate) your expressions.
  1103.  * We do however strip off and decode addressing modes and operation
  1104.  * mnemonic.
  1105.  *
  1106.  * This function's value is a string. If it is not "" then an internal
  1107.  * logic error was found: read this code to assign meaning to the string.
  1108.  * No argument string should generate such an error string:
  1109.  * it means a bug in our code, not in the user's text.
  1110.  *
  1111.  * You MUST have called m86_ip_begin() once and m86_ip_end() never before using
  1112.  * this function.
  1113.  */
  1114.  
  1115. /* JF this function no longer returns a useful value.  Sorry */
  1116. void
  1117. m68_ip (instring)
  1118. char    *instring;
  1119. {
  1120.     register char *p;
  1121.     register struct m68k_op *opP;
  1122.     register struct m68_incant *opcode;
  1123.     register char *s;
  1124.     register int tmpreg,
  1125.         baseo,
  1126.         outro,
  1127.         nextword;
  1128.     int    siz1,
  1129.         siz2;
  1130.     char    c;
  1131.     int    losing;
  1132.     int    opsfound;
  1133.     char    *crack_operand();
  1134.     LITTLENUM_TYPE words[6];
  1135.     LITTLENUM_TYPE *wordp;
  1136.  
  1137.     if (*instring == ' ')
  1138.         instring++;            /* skip leading whitespace */
  1139.  
  1140.   /* Scan up to end of operation-code, which MUST end in end-of-string
  1141.      or exactly 1 space. */
  1142.     for (p = instring; *p != '\0'; p++)
  1143. #if defined(CANON) && defined(SUN_ASM_SYNTAX)
  1144.         /*
  1145.          * On SUN's Assembler, an operator and operands can be
  1146.          * separeted by spaces or tabs. (Shin)
  1147.          */
  1148.         if (*p == ' ' || *p == '\t')
  1149. #else
  1150.         if (*p == ' ')
  1151. #endif CANON && SUN_ASUM_SYNTAX
  1152.             break;
  1153.  
  1154.  
  1155.     if (p == instring) {
  1156.         the_ins.error = "No operator";
  1157.         the_ins.opcode[0] = NULL;
  1158.         /* the_ins.numo=1; */
  1159.         return;
  1160.     }
  1161.  
  1162.   /* p now points to the end of the opcode name, probably whitespace.
  1163.      make sure the name is null terminated by clobbering the whitespace,
  1164.      look it up in the hash table, then fix it back. */   
  1165.     c = *p;
  1166.     *p = '\0';
  1167. #ifdef m68040
  1168.     if (m68k_kind == 4 && (
  1169.              (instring[0] == 'f' && indirect_fp_inst(instring))
  1170.             || m68020_only_inst(instring) )){
  1171.         opcode = NULL;
  1172.     } else
  1173. #endif m68040
  1174.     opcode = (struct m68_incant *)hash_find (op_hash, instring);
  1175.     *p = c;
  1176.  
  1177.     if (opcode == NULL) {
  1178.         the_ins.error = "Unknown operator";
  1179.         the_ins.opcode[0] = NULL;
  1180.         /* the_ins.numo=1; */
  1181.         return;
  1182.     }
  1183.  
  1184. #if defined(CANON) && defined(SUN_ASM_SYNTAX)
  1185.     for (; *p != '\0'; p++)
  1186.         if (!(*p == ' ' || *p == '\t'))
  1187.             break;
  1188. #endif CANON && SUN_ASM_SYNTAX
  1189.  
  1190.   /* found a legitimate opcode, start matching operands */
  1191.     for(opP= &the_ins.operands[0];*p;opP++) {
  1192.         p = crack_operand (p, opP);
  1193.         if(opP->error) {
  1194.             the_ins.error=opP->error;
  1195.             return;
  1196.         }
  1197.     }
  1198.  
  1199.     opsfound=opP- &the_ins.operands[0];
  1200.     /* This ugly hack is to support the floating pt opcodes in their standard form */
  1201.     /* Essentially, we fake a first enty of type COP#1 */
  1202.     if(opcode->m_operands[0]=='I') {
  1203.         int    n;
  1204.  
  1205.         for(n=opsfound;n>0;--n)
  1206.             the_ins.operands[n]=the_ins.operands[n-1];
  1207.  
  1208.         /* bcopy((char *)(&the_ins.operands[0]),(char *)(&the_ins.operands[1]),opsfound*sizeof(the_ins.operands[0])); */
  1209.         bzero((char *)(&the_ins.operands[0]),sizeof(the_ins.operands[0]));
  1210.         the_ins.operands[0].mode=MSCR;
  1211.         the_ins.operands[0].reg=COPNUM;        /* COP #1 */
  1212.         opsfound++;
  1213.     }
  1214.         /* We've got the operands.  Find an opcode that'll
  1215.            accept them */
  1216.     for(losing=0;;) {
  1217.         if(opsfound!=opcode->m_opnum)
  1218.             losing++;
  1219.         else for(s=opcode->m_operands,opP= &the_ins.operands[0];*s && !losing;s+=2,opP++) {
  1220.                 /* Warning: this switch is huge! */
  1221.                 /* I've tried to organize the cases into  this order:
  1222.                    non-alpha first, then alpha by letter.  lower-case goes directly
  1223.                    before uppercase counterpart. */
  1224.                 /* Code with multiple case ...: gets sorted by the lowest case ...
  1225.                    it belongs to.  I hope this makes sense. */
  1226.             switch(*s) {
  1227.             case '!':
  1228.                 if(opP->mode==MSCR || opP->mode==IMMED ||
  1229.  opP->mode==DREG || opP->mode==AREG || opP->mode==AINC || opP->mode==ADEC || opP->mode==REGLST)
  1230.                     losing++;
  1231.                 break;
  1232.  
  1233.             case '#':
  1234.                 if(opP->mode!=IMMED)
  1235.                     losing++;
  1236.                 else {
  1237.                     long t;
  1238.  
  1239.                     t=get_num(opP->con1,80);
  1240.                     if(s[1]=='b' && !isbyte(t))
  1241.                         losing++;
  1242.                     else if(s[1]=='w' && !isword(t))
  1243.                         losing++;
  1244.                 }
  1245.                 break;
  1246.  
  1247.             case '^':
  1248.             case 'T':
  1249.                 if(opP->mode!=IMMED)
  1250.                     losing++;
  1251.                 break;
  1252.  
  1253.             case '$':
  1254.                 if(opP->mode==MSCR || opP->mode==AREG ||
  1255.  opP->mode==IMMED || opP->reg==PC || opP->reg==ZPC || opP->mode==REGLST)
  1256.                     losing++;
  1257.                 break;
  1258.  
  1259.             case '%':
  1260.                 if(opP->mode==MSCR || opP->reg==PC ||
  1261.  opP->reg==ZPC || opP->mode==REGLST)
  1262.                     losing++;
  1263.                 break;
  1264.  
  1265.  
  1266.             case '&':
  1267.                 if(opP->mode==MSCR || opP->mode==DREG ||
  1268.  opP->mode==AREG || opP->mode==IMMED || opP->reg==PC || opP->reg==ZPC ||
  1269.  opP->mode==AINC || opP->mode==ADEC || opP->mode==REGLST)
  1270.                     losing++;
  1271.                 break;
  1272.  
  1273.             case '*':
  1274.                 if(opP->mode==MSCR || opP->mode==REGLST)
  1275.                     losing++;
  1276.                 break;
  1277.  
  1278.             case '+':
  1279.                 if(opP->mode!=AINC)
  1280.                     losing++;
  1281.                 break;
  1282.  
  1283.             case '-':
  1284.                 if(opP->mode!=ADEC)
  1285.                     losing++;
  1286.                 break;
  1287.  
  1288.             case '/':
  1289.                 if(opP->mode==MSCR || opP->mode==AREG ||
  1290.  opP->mode==AINC || opP->mode==ADEC || opP->mode==IMMED || opP->mode==REGLST)
  1291.                     losing++;
  1292.                 break;
  1293.  
  1294.             case ';':
  1295.                 if(opP->mode==MSCR || opP->mode==AREG || opP->mode==REGLST)
  1296.                     losing++;
  1297.                 break;
  1298.  
  1299.             case '?':
  1300.                 if(opP->mode==MSCR || opP->mode==AREG ||
  1301.  opP->mode==AINC || opP->mode==ADEC || opP->mode==IMMED || opP->reg==PC ||
  1302.  opP->reg==ZPC || opP->mode==REGLST)
  1303.                     losing++;
  1304.                 break;
  1305.  
  1306.             case '@':
  1307.                 if(opP->mode==MSCR || opP->mode==AREG ||
  1308.  opP->mode==IMMED || opP->mode==REGLST)
  1309.                     losing++;
  1310.                 break;
  1311.  
  1312.             case '~':        /* For now! (JF FOO is this right?) */
  1313.                 if(opP->mode==MSCR || opP->mode==DREG ||
  1314.  opP->mode==AREG || opP->mode==IMMED || opP->reg==PC || opP->reg==ZPC || opP->mode==REGLST)
  1315.                     losing++;
  1316.                 break;
  1317.  
  1318. #ifdef m68040
  1319.             case 'a':
  1320.                 if(opP->mode!=AINDR)
  1321.                     losing++;
  1322.                 break;
  1323. #endif m68040
  1324.             case 'A':
  1325.                 if(opP->mode!=AREG)
  1326.                     losing++;
  1327.                 break;
  1328.  
  1329.             case 'B':    /* FOO */
  1330.                 if(opP->mode!=ABSL)
  1331.                     losing++;
  1332.                 break;
  1333. #ifdef m68040
  1334.             case 'c':
  1335.                 if(opP->mode!=MSCR || opP->reg<NC || opP->reg>BC)
  1336.                     losing++;
  1337.                 break;
  1338.  
  1339. #endif
  1340.  
  1341.             case 'C':
  1342.                 if(opP->mode!=MSCR || opP->reg!=CCR)
  1343.                     losing++;
  1344.                 break;
  1345.  
  1346.             case 'd':    /* FOO This mode is a KLUDGE!! */
  1347.                 if(opP->mode!=AOFF && (opP->mode!=ABSL ||
  1348.  opP->con1->e_beg[0]!='(' || opP->con1->e_end[0]!=')'))
  1349.                     losing++;
  1350.                 break;
  1351.  
  1352.             case 'D':
  1353.                 if(opP->mode!=DREG)
  1354.                     losing++;
  1355.                 break;
  1356.  
  1357.             case 'F':
  1358.                 if(opP->mode!=MSCR || opP->reg<(FPREG+0) || opP->reg>(FPREG+7))
  1359.                     losing++;
  1360.                 break;
  1361.  
  1362.             case 'I':
  1363.                 if(opP->mode!=MSCR || opP->reg<COPNUM ||
  1364.  opP->reg>=COPNUM+7)
  1365.                     losing++;
  1366.                 break;
  1367.  
  1368.             case 'J':
  1369. #ifdef m68040
  1370.                 if(opP->mode!=MSCR ||
  1371.                    ((opP->reg<USP && opP->reg>MSP) &&
  1372.                     (opP->reg<TC && opP->reg>SRP)))
  1373. #else
  1374.                 if(opP->mode!=MSCR || opP->reg<USP || opP->reg>MSP)
  1375. #endif m68040
  1376.                     losing++;
  1377.                 break;
  1378.  
  1379.             case 'k':
  1380.                 if(opP->mode!=IMMED)
  1381.                     losing++;
  1382.                 break;
  1383.  
  1384.             case 'l':
  1385.             case 'L':
  1386.                 if(opP->mode==DREG || opP->mode==AREG || opP->mode==FPREG) {
  1387.                     if(s[1]=='8')
  1388.                         losing++;
  1389.                     else {
  1390.                         opP->mode=REGLST;
  1391.                         opP->reg=1<<(opP->reg-DATA);
  1392.                     }
  1393.                 } else if(opP->mode!=REGLST) {
  1394.                     losing++;
  1395.                 } else if(s[1]=='8' && opP->reg&0x0FFffFF)
  1396.                     losing++;
  1397.                 else if(s[1]=='3' && opP->reg&0x7000000)
  1398.                     losing++;
  1399.                 break;
  1400.  
  1401.             case 'M':
  1402.                 if(opP->mode!=IMMED)
  1403.                     losing++;
  1404.                 else {
  1405.                     long t;
  1406.  
  1407.                     t=get_num(opP->con1,80);
  1408.                     if(!issbyte(t) || isvar(opP->con1))
  1409.                         losing++;
  1410.                 }
  1411.                 break;
  1412.  
  1413.             case 'O':
  1414.                 if(opP->mode!=DREG && opP->mode!=IMMED)
  1415.                     losing++;
  1416.                 break;
  1417.  
  1418.             case 'Q':
  1419.                 if(opP->mode!=IMMED)
  1420.                     losing++;
  1421.                 else {
  1422.                     long t;
  1423.  
  1424.                     t=get_num(opP->con1,80);
  1425.                     if (s[1]!='s') {
  1426.                         if(t<1 || t>8 || isvar(opP->con1))
  1427.                             losing++;
  1428.                     }
  1429.                     else {
  1430.                         if(t<0 || t>7 || isvar(opP->con1))
  1431.                             losing++;
  1432.                     }
  1433.                 }
  1434.                 break;
  1435.  
  1436.             case 'R':
  1437.                 if(opP->mode!=DREG && opP->mode!=AREG)
  1438.                     losing++;
  1439.                 break;
  1440.  
  1441.             case 's':
  1442.                 if(opP->mode!=MSCR || !(opP->reg==FPI || opP->reg==FPS || opP->reg==FPC))
  1443.                     losing++;
  1444.                 break;
  1445.  
  1446.             case 'S':
  1447.                 if(opP->mode!=MSCR || opP->reg!=SR)
  1448.                     losing++;
  1449.                 break;
  1450.  
  1451.             case 'U':
  1452.                 if(opP->mode!=MSCR || opP->reg!=USP)
  1453.                     losing++;
  1454.                 break;
  1455.  
  1456.             /* JF these are out of order.  We could put them
  1457.                in order if we were willing to put up with
  1458.                bunches of #ifdef m68851s in the code */
  1459. #ifdef m68851
  1460.             /* Memory addressing mode used by pflushr */
  1461.             case '|':
  1462.                 if(opP->mode==MSCR || opP->mode==DREG ||
  1463.  opP->mode==AREG || opP->mode==REGLST)
  1464.                     losing++;
  1465.                 break;
  1466.  
  1467.             case 'f':
  1468.                 if (opP->mode != MSCR || (opP->reg != SFC && opP->reg != DFC))
  1469.                     losing++;
  1470.                 break;
  1471.  
  1472.             case 'P':
  1473.                 if (opP->mode != MSCR || (opP->reg != TC && opP->reg != CAL &&
  1474.                     opP->reg != VAL && opP->reg != SCC && opP->reg != AC))
  1475.                     losing++;
  1476.                 break;
  1477.  
  1478.             case 'V':
  1479.                 if (opP->reg != VAL)
  1480.                     losing++;
  1481.                 break;
  1482.  
  1483.             case 'W':
  1484.                 if (opP->mode != MSCR || (opP->reg != DRP && opP->reg != SRP &&
  1485.                     opP->reg != CRP))
  1486.                     losing++;
  1487.                 break;
  1488.  
  1489.             case 'X':
  1490.                 if (opP->mode != MSCR ||
  1491.                     (!(opP->reg >= BAD && opP->reg <= BAD+7) &&
  1492.                      !(opP->reg >= BAC && opP->reg <= BAC+7)))
  1493.                     losing++;
  1494.                 break;
  1495.  
  1496.             case 'Y':
  1497.                 if (opP->reg != PSR)
  1498.                     losing++;
  1499.                 break;
  1500.  
  1501.             case 'Z':
  1502.                 if (opP->reg != PCSR)
  1503.                     losing++;
  1504.                 break;
  1505. #endif
  1506.             default:
  1507.                 as_fatal("Internal error:  Operand mode %c unknown",*s);
  1508.             }
  1509.         }
  1510.         if(!losing)
  1511.             break;
  1512.         opcode=opcode->m_next;
  1513.         if(!opcode) {        /* Fell off the end */
  1514.             the_ins.error="instruction/operands mismatch";
  1515.             return;
  1516.         }
  1517.         losing=0;
  1518.     }
  1519.     the_ins.args=opcode->m_operands;
  1520.     the_ins.numargs=opcode->m_opnum;
  1521.     the_ins.numo=opcode->m_codenum;
  1522.     the_ins.opcode[0]=getone(opcode);
  1523.     the_ins.opcode[1]=gettwo(opcode);
  1524.  
  1525.     for(s=the_ins.args,opP= &the_ins.operands[0];*s;s+=2,opP++) {
  1526.             /* This switch is a doozy.
  1527.                What the first step; its a big one! */
  1528.         switch(s[0]) {
  1529.         case '*':
  1530.         case '~':
  1531.         case '%':
  1532.         case ';':
  1533.         case '@':
  1534.         case '!':
  1535.         case '&':
  1536.         case '$':
  1537.         case '?':
  1538.         case '/':
  1539. #ifdef m68851
  1540.         case '|':
  1541. #endif
  1542.             switch(opP->mode) {
  1543.             case IMMED:
  1544.                 tmpreg=0x3c;    /* 7.4 */
  1545.                 if(index("bwl",s[1])) nextword=get_num(opP->con1,80);
  1546.                 else nextword=nextword=get_num(opP->con1,0);
  1547.                 if(isvar(opP->con1))
  1548.                     add_fix(s[1],opP->con1,0);
  1549.                 switch(s[1]) {
  1550.                 case 'b':
  1551.                     if(!isbyte(nextword))
  1552.                         opP->error="operand out of range";
  1553.                     addword(nextword);
  1554.                     baseo=0;
  1555.                     break;
  1556.                 case 'w':
  1557.                     if(!isword(nextword))
  1558.                         opP->error="operand out of range";
  1559.                     addword(nextword);
  1560.                     baseo=0;
  1561.                     break;
  1562.                 case 'l':
  1563.                     addword(nextword>>16);
  1564.                     addword(nextword);
  1565.                     baseo=0;
  1566.                     break;
  1567.  
  1568.                 case 'f':
  1569.                     baseo=2;
  1570.                     outro=8;
  1571.                     break;
  1572.                 case 'F':
  1573.                     baseo=4;
  1574.                     outro=11;
  1575.                     break;
  1576.                 case 'x':
  1577.                     baseo=6;
  1578.                     outro=15;
  1579.                     break;
  1580.                 case 'p':
  1581.                     baseo=6;
  1582.                     outro= -1;
  1583.                     break;
  1584.                 default:
  1585.                     as_fatal("Internal error:  Can't decode %c%c",*s,s[1]);
  1586.                 }
  1587.                 if(!baseo)
  1588.                     break;
  1589.  
  1590.                 /* We gotta put out some float */
  1591.                 if(seg(opP->con1)!=SEG_BIG) {
  1592.                     int_to_gen(nextword);
  1593.                     gen_to_words(words,baseo,(long int)outro);
  1594.                     for(wordp=words;baseo--;wordp++)
  1595.                         addword(*wordp);
  1596.                     break;
  1597.                 }        /* Its BIG */
  1598.                 if(offs(opP->con1)>0) {
  1599.                     as_warn("Bignum assumed to be binary bit-pattern");
  1600.                     if(offs(opP->con1)>baseo) {
  1601.                         as_warn("Bignum too big for %c format; truncated",s[1]);
  1602.                         offs(opP->con1)=baseo;
  1603.                     }
  1604.                     baseo-=offs(opP->con1);
  1605.                     for(wordp=generic_bignum+offs(opP->con1)-1;offs(opP->con1)--;--wordp)
  1606.                         addword(*wordp);
  1607.                     while(baseo--)
  1608.                         addword(0);
  1609.                     break;
  1610.                 }
  1611.                 gen_to_words(words,baseo,(long int)outro);
  1612.                 for(wordp=words;baseo--;wordp++)
  1613.                     addword(*wordp);
  1614.                 break;
  1615.             case DREG:
  1616.                 tmpreg=opP->reg-DATA; /* 0.dreg */
  1617.                 break;
  1618.             case AREG:
  1619.                 tmpreg=0x08+opP->reg-ADDR; /* 1.areg */
  1620.                 break;
  1621.             case AINDR:
  1622.                 tmpreg=0x10+opP->reg-ADDR; /* 2.areg */
  1623.                 break;
  1624.             case ADEC:
  1625.                 tmpreg=0x20+opP->reg-ADDR; /* 4.areg */
  1626.                 break;
  1627.             case AINC:
  1628.                 tmpreg=0x18+opP->reg-ADDR; /* 3.areg */
  1629.                 break;
  1630.             case AOFF:
  1631.  
  1632.                 nextword=get_num(opP->con1,80);
  1633.                 /* Force into index mode.  Hope this works */
  1634.  
  1635.                 /* We do the first bit for 32-bit displacements,
  1636.                    and the second bit for 16 bit ones.  It is
  1637.                    possible that we should make the default be
  1638.                    WORD instead of LONG, but I think that'd
  1639.                    break GCC, so we put up with a little
  1640.                    inefficiency for the sake of working output.
  1641.                  */
  1642.  
  1643.                 if(   !issword(nextword)
  1644.                    || (   isvar(opP->con1)
  1645.                        && (  (   opP->con1->e_siz==0
  1646.                           && flagseen['l']!=0)
  1647.                        || opP->con1->e_siz==3))) {
  1648.  
  1649.                     if(opP->reg==PC)
  1650.                         tmpreg=0x3B;    /* 7.3 */
  1651.                     else
  1652.                         tmpreg=0x30+opP->reg-ADDR;    /* 6.areg */
  1653.                     if(isvar(opP->con1)) {
  1654.                         if(opP->reg==PC) {
  1655.                                add_frag(adds(opP->con1),
  1656.                              offs(opP->con1),
  1657.                              TAB(PCLEA,SZ_UNDEF));
  1658.                             break;
  1659.                         } else {
  1660.                             addword(0x0170);
  1661.                             add_fix('l',opP->con1,0);
  1662.                         }
  1663.                     } else
  1664.                         addword(0x0170);
  1665.                     addword(nextword>>16);
  1666.                 } else {
  1667.                     if(opP->reg==PC)
  1668.                         tmpreg=0x3A; /* 7.2 */
  1669.                     else
  1670.                         tmpreg=0x28+opP->reg-ADDR; /* 5.areg */
  1671.  
  1672.                     if(isvar(opP->con1)) {
  1673.                         if(opP->reg==PC) {
  1674.                             add_fix('w',opP->con1,1);
  1675.                         } else
  1676.                             add_fix('w',opP->con1,0);
  1677.                         }
  1678.                 }
  1679.                 addword(nextword);
  1680.                 break;
  1681.             case AINDX:
  1682.             case APODX:
  1683.             case AMIND:
  1684.             case APRDX:
  1685.                 nextword=0;
  1686.                 baseo=get_num(opP->con1,80);
  1687.                 outro=get_num(opP->con2,80);
  1688.                     /* Figure out the 'addressing mode' */
  1689.                     /* Also turn on the BASE_DISABLE bit, if needed */
  1690.                 if(opP->reg==PC || opP->reg==ZPC) {
  1691.                     tmpreg=0x3b; /* 7.3 */
  1692.                     if(opP->reg==ZPC)
  1693.                         nextword|=0x80;
  1694.                 } else if(opP->reg==FAIL) {
  1695.                     nextword|=0x80;
  1696.                     tmpreg=0x30;    /* 6.garbage */
  1697.                 } else tmpreg=0x30+opP->reg-ADDR; /* 6.areg */
  1698.  
  1699.                 siz1= (opP->con1) ? opP->con1->e_siz : 0;
  1700.                 siz2= (opP->con2) ? opP->con2->e_siz : 0;
  1701.  
  1702.                     /* Index register stuff */
  1703.                 if(opP->ireg>=DATA+0 && opP->ireg<=ADDR+7) {
  1704.                     nextword|=(opP->ireg-DATA)<<12;
  1705.  
  1706.                     if(opP->isiz==0 || opP->isiz==3)
  1707.                         nextword|=0x800;
  1708.                     switch(opP->imul) {
  1709.                     case 1: break;
  1710.                     case 2: nextword|=0x200; break;
  1711.                     case 4: nextword|=0x400; break;
  1712.                     case 8: nextword|=0x600; break;
  1713.                     default: abort();
  1714.                     }
  1715.                         /* IF its simple,
  1716.                            GET US OUT OF HERE! */
  1717.  
  1718.                         /* Must be INDEX, with an index
  1719.                            register.  Address register
  1720.                            cannot be ZERO-PC, and either
  1721.                            :b was forced, or we know
  1722.                            it will fit */
  1723.                     if(   opP->mode==AINDX
  1724.                        && opP->reg!=FAIL
  1725.                        && opP->reg!=ZPC
  1726.                        && (   siz1==1
  1727.                            || (   issbyte(baseo)
  1728.                            && !isvar(opP->con1)))) {
  1729.                         nextword +=baseo&0xff;
  1730.                         addword(nextword);
  1731.                         if(isvar(opP->con1))
  1732.                             add_fix('B',opP->con1,0);
  1733.                         break;
  1734.                     }
  1735.                 } else
  1736.                     nextword|=0x40;    /* No index reg */
  1737.  
  1738.                     /* It aint simple */
  1739.                 nextword|=0x100;
  1740.                     /* If the guy specified a width, we assume that
  1741.                        it is wide enough.  Maybe it isn't.  Ifso, we lose
  1742.                      */
  1743.                 switch(siz1) {
  1744.                 case 0:
  1745.                     if(isvar(opP->con1) || !issword(baseo)) {
  1746.                         siz1=3;
  1747.                         nextword|=0x30;
  1748.                     } else if(baseo==0)
  1749.                         nextword|=0x10;
  1750.                     else {    
  1751.                         nextword|=0x20;
  1752.                         siz1=2;
  1753.                     }
  1754.                     break;
  1755.                 case 1:
  1756.                     as_warn("Byte dispacement won't work.  Defaulting to :w");
  1757.                 case 2:
  1758.                     nextword|=0x20;
  1759.                     break;
  1760.                 case 3:
  1761.                     nextword|=0x30;
  1762.                     break;
  1763.                 }
  1764.  
  1765.                     /* Figure out innner displacement stuff */
  1766.                 if(opP->mode!=AINDX) {
  1767.                     switch(siz2) {
  1768.                     case 0:
  1769.                         if(isvar(opP->con2) || !issword(outro)) {
  1770.                             siz2=3;
  1771.                             nextword|=0x3;
  1772.                         } else if(outro==0)
  1773.                             nextword|=0x1;
  1774.                         else {    
  1775.                             nextword|=0x2;
  1776.                             siz2=2;
  1777.                         }
  1778.                         break;
  1779.                     case 1:
  1780.                         as_warn("Byte dispacement won't work.  Defaulting to :w");
  1781.                     case 2:
  1782.                         nextword|=0x2;
  1783.                         break;
  1784.                     case 3:
  1785.                         nextword|=0x3;
  1786.                         break;
  1787.                     }
  1788.                     if(opP->mode==APODX) nextword|=0x04;
  1789.                     else if(opP->mode==AMIND) nextword|=0x40;
  1790.                 }
  1791.                 addword(nextword);
  1792.  
  1793.                 if(isvar(opP->con1)) {
  1794.                     if(opP->reg==PC || opP->reg==ZPC) {
  1795.                         add_fix(siz1==3 ? 'l' : 'w',opP->con1,1);
  1796.                         opP->con1->e_exp.X_add_number+=6;
  1797.                     } else
  1798.                         add_fix(siz1==3 ? 'l' : 'w',opP->con1,0);
  1799.                 }
  1800.                 if(siz1==3)
  1801.                     addword(baseo>>16);
  1802.                 if(siz1)
  1803.                     addword(baseo);
  1804.  
  1805.                 if(isvar(opP->con2)) {
  1806.                     if(opP->reg==PC || opP->reg==ZPC) {
  1807.                         add_fix(siz2==3 ? 'l' : 'w',opP->con2,1);
  1808.                         opP->con1->e_exp.X_add_number+=6;
  1809.                     } else
  1810.                         add_fix(siz2==3 ? 'l' : 'w',opP->con2,0);
  1811.                 }
  1812.                 if(siz2==3)
  1813.                     addword(outro>>16);
  1814.                 if(siz2)
  1815.                     addword(outro);
  1816.  
  1817.                 break;
  1818.  
  1819.             case ABSL:
  1820.                 nextword=get_num(opP->con1,80);
  1821.                 switch(opP->con1->e_siz) {
  1822.                 default:
  1823.                     as_warn("Unknown size for absolute reference");
  1824.                 case 0:
  1825.                     if(!isvar(opP->con1) && issword(offs(opP->con1))) {
  1826.                         tmpreg=0x38; /* 7.0 */
  1827.                         addword(nextword);
  1828.                         break;
  1829.                     }
  1830.                     /* Don't generate pc relative code
  1831.                        on 68010 and 68000 */
  1832.                     if(isvar(opP->con1) &&
  1833.                        !subs(opP->con1) &&
  1834.                        seg(opP->con1)==SEG_TEXT &&
  1835.                        now_seg==SEG_TEXT &&
  1836.                        flagseen['m']==0 &&
  1837.                         !index("~%&$?", s[0])) {
  1838.                         tmpreg=0x3A; /* 7.2 */
  1839.                         add_frag(adds(opP->con1),
  1840.                              offs(opP->con1),
  1841.                              TAB(PCREL,SZ_UNDEF));
  1842.                         break;
  1843.                     }
  1844.                 case 3:        /* Fall through into long */
  1845.                     if(isvar(opP->con1))
  1846.                         add_fix('l',opP->con1,0);
  1847.  
  1848.                     tmpreg=0x39;    /* 7.1 mode */
  1849.                     addword(nextword>>16);
  1850.                     addword(nextword);
  1851.                     break;
  1852.  
  1853.                 case 2:        /* Word */
  1854.                     if(isvar(opP->con1))
  1855.                         add_fix('w',opP->con1,0);
  1856.  
  1857.                     tmpreg=0x38;    /* 7.0 mode */
  1858.                     addword(nextword);
  1859.                     break;
  1860.                 }
  1861.                 break;
  1862.             case MSCR:
  1863.             default:
  1864.                 as_bad("unknown/incorrect operand");
  1865.                 /* abort(); */
  1866.             }
  1867.             install_gen_operand(s[1],tmpreg);
  1868.             break;
  1869.  
  1870.         case '#':
  1871.         case '^':
  1872.             switch(s[1]) {    /* JF: I hate floating point! */
  1873.             case 'j':
  1874.                 tmpreg=70;
  1875.                 break;
  1876.             case '8':
  1877.                 tmpreg=20;
  1878.                 break;
  1879.             case 'C':
  1880.                 tmpreg=50;
  1881.                 break;
  1882.             case '3':
  1883.             default:
  1884.                 tmpreg=80;
  1885.                 break;
  1886.             }
  1887.             tmpreg=get_num(opP->con1,tmpreg);
  1888.             if(isvar(opP->con1))
  1889.                 add_fix(s[1],opP->con1,0);
  1890.             switch(s[1]) {
  1891.             case 'b':    /* Danger:  These do no check for
  1892.                        certain types of overflow.
  1893.                        user beware! */
  1894.                 if(!isbyte(tmpreg))
  1895.                     opP->error="out of range";
  1896.                 insop(tmpreg);
  1897.                 if(isvar(opP->con1))
  1898.                     the_ins.reloc[the_ins.nrel-1].n=(opcode->m_codenum)*2;
  1899.                 break;
  1900.             case 'w':
  1901.                 if(!isword(tmpreg))
  1902.                     opP->error="out of range";
  1903.                 insop(tmpreg);
  1904.                 if(isvar(opP->con1))
  1905.                     the_ins.reloc[the_ins.nrel-1].n=(opcode->m_codenum)*2;
  1906.                 break;
  1907.             case 'l':
  1908.                 insop(tmpreg);        /* Because of the way insop works, we put these two out backwards */
  1909.                 insop(tmpreg>>16);
  1910.                 if(isvar(opP->con1))
  1911.                     the_ins.reloc[the_ins.nrel-1].n=(opcode->m_codenum)*2;
  1912.                 break;
  1913.             case '3':
  1914.                 tmpreg&=0xFF;
  1915.             case '8':
  1916.             case 'C':
  1917.                 install_operand(s[1],tmpreg);
  1918.                 break;
  1919.             default:
  1920.                 as_fatal("Internal error:  Unknown mode #%c",s[1]);
  1921.             }
  1922.             break;
  1923.  
  1924.         case '+':
  1925.         case '-':
  1926.         case 'A':
  1927. #ifdef m68040
  1928.         case 'a':
  1929. #endif m68040
  1930.             install_operand(s[1],opP->reg-ADDR);
  1931.             break;
  1932.  
  1933.         case 'B':
  1934.             tmpreg=get_num(opP->con1,80);
  1935.             switch(s[1]) {
  1936.             case 'g':
  1937.                 if(opP->con1->e_siz) {    /* Deal with fixed size stuff by hand */
  1938.                     switch(opP->con1->e_siz) {
  1939.                     case 1:
  1940.                         add_fix('b',opP->con1,1);
  1941.                         break;
  1942.                     case 2:
  1943.                         add_fix('w',opP->con1,1);
  1944.                         addword(0);
  1945.                         break;
  1946.                     case 3:
  1947.                         add_fix('l',opP->con1,1);
  1948.                         addword(0);
  1949.                         addword(0);
  1950.                         break;
  1951.                     default:
  1952.                         as_fatal("Bad size for expression %d",opP->con1->e_siz);
  1953.                     }
  1954.                 } else if(subs(opP->con1)) {
  1955.                         /* We can't relax it */
  1956.                     the_ins.opcode[the_ins.numo-1]|=0xff;
  1957.                     add_fix('l',opP->con1,1);
  1958.                     addword(0);
  1959.                     addword(0);
  1960.                 } else if(adds(opP->con1)) {
  1961.                     if (flagseen['m'] && 
  1962.                         (the_ins.opcode[0] >= 0x6200) &&
  1963.                         (the_ins.opcode[0] <= 0x6f00)) {
  1964.                       add_frag(adds(opP->con1),offs(opP->con1),TAB(BCC68000,SZ_UNDEF));
  1965.                     } else {
  1966.                         add_frag(adds(opP->con1),offs(opP->con1),TAB(BRANCH,SZ_UNDEF));
  1967.                     }
  1968.                 } else {
  1969.                     /* JF:  This is the WRONG thing to do
  1970.                     add_frag((symbolS *)0,offs(opP->con1),TAB(BRANCH,BYTE)); */
  1971.                     the_ins.opcode[the_ins.numo-1]|=0xff;
  1972.                     offs(opP->con1)+=4;
  1973.                     add_fix('l',opP->con1,1);
  1974.                     addword(0);
  1975.                     addword(0);
  1976.                 }
  1977.                 break;
  1978.             case 'w':
  1979.                 if(isvar(opP->con1)) {
  1980.                     /* check for DBcc instruction */
  1981.                     if ((the_ins.opcode[0] & 0xf0f8) ==0x50c8) {
  1982.                         /* size varies if patch */
  1983.                         /* needed for long form */
  1984.                         add_frag(adds(opP->con1),offs(opP->con1),TAB(DBCC,SZ_UNDEF));
  1985.                         break;
  1986.                     }
  1987.  
  1988.                         /* Don't ask! */
  1989.                     opP->con1->e_exp.X_add_number+=2;
  1990.                     add_fix('w',opP->con1,1);
  1991.                 }
  1992.                 addword(0);
  1993.                 break;
  1994.             case 'c':
  1995.                 if(opP->con1->e_siz) {
  1996.                     switch(opP->con1->e_siz) {
  1997.                     case 2:
  1998.                         add_fix('w',opP->con1,1)
  1999.                         addword(0);
  2000.                         break;
  2001.                     case 3:
  2002.                         the_ins.opcode[the_ins.numo-1]|=0x40;
  2003.                         add_fix('l',opP->con1,1);
  2004.                         addword(0);
  2005.                         addword(0);
  2006.                         break;
  2007.                     default:
  2008.                         as_bad("Bad size for offset, must be word or long");
  2009.                         break;
  2010.                     }
  2011.                 } else if(subs(opP->con1)) {
  2012.                     add_fix('l',opP->con1,1);
  2013.                     add_frag((symbolS *)0,(long)0,TAB(FBRANCH,LONG));
  2014.                 } else if(adds(opP->con1)) {
  2015.                     add_frag(adds(opP->con1),offs(opP->con1),TAB(FBRANCH,SZ_UNDEF));
  2016.                 } else {
  2017.                     /* add_frag((symbolS *)0,offs(opP->con1),TAB(FBRANCH,SHORT)); */
  2018.                     the_ins.opcode[the_ins.numo-1]|=0x40;
  2019.                     add_fix('l',opP->con1,1);
  2020.                     addword(0);
  2021.                     addword(4);
  2022.                 }
  2023.                 break;
  2024.             default:
  2025.                 as_fatal("Internal error:  operand type B%c unknown",s[1]);
  2026.             }
  2027.             break;
  2028.  
  2029. #ifdef m68040
  2030.         case 'c':
  2031.             install_operand(s[1],opP->reg-NC);
  2032.             break;
  2033. #endif m68040
  2034.  
  2035.         case 'C':        /* Ignore it */
  2036.             break;
  2037.  
  2038.         case 'd':        /* JF this is a kludge */
  2039.             if(opP->mode==AOFF) {
  2040.                 install_operand('s',opP->reg-ADDR);
  2041.             } else {
  2042.                 char *tmpP;
  2043.  
  2044.                 tmpP=opP->con1->e_end-2;
  2045.                 opP->con1->e_beg++;
  2046.                 opP->con1->e_end-=4;    /* point to the , */
  2047.                 baseo=m68k_reg_parse(&tmpP);
  2048.                 if(baseo<ADDR+0 || baseo>ADDR+7) {
  2049.                     as_bad("Unknown address reg, using A0");
  2050.                     baseo=0;
  2051.                 } else baseo-=ADDR;
  2052.                 install_operand('s',baseo);
  2053.             }
  2054.             tmpreg=get_num(opP->con1,80);
  2055.             if(!issword(tmpreg)) {
  2056.                 as_warn("Expression out of range, using 0");
  2057.                 tmpreg=0;
  2058.             }
  2059.             addword(tmpreg);
  2060.             break;
  2061.  
  2062.         case 'D':
  2063.             install_operand(s[1],opP->reg-DATA);
  2064.             break;
  2065.  
  2066.         case 'F':
  2067.             install_operand(s[1],opP->reg-FPREG);
  2068.             break;
  2069.  
  2070.         case 'I':
  2071.             tmpreg=1+opP->reg-COPNUM;
  2072.             if(tmpreg==8)
  2073.                 tmpreg=0;
  2074.             install_operand(s[1],tmpreg);
  2075.             break;
  2076.  
  2077.         case 'J':        /* JF foo */
  2078.             switch(opP->reg) {
  2079.             case SFC:
  2080.                 tmpreg=0;
  2081.                 break;
  2082.             case DFC:
  2083.                 tmpreg=0x001;
  2084.                 break;
  2085.             case CACR:
  2086.                 tmpreg=0x002;
  2087.                 break;
  2088.             case USP:
  2089.                 tmpreg=0x800;
  2090.                 break;
  2091.             case VBR:
  2092.                 tmpreg=0x801;
  2093.                 break;
  2094.             case CAAR:
  2095.                 tmpreg=0x802;
  2096.                 break;
  2097.             case MSP:
  2098.                 tmpreg=0x803;
  2099.                 break;
  2100.             case ISP:
  2101.                 tmpreg=0x804;
  2102.                 break;
  2103. #ifdef m68040
  2104.             case TC:
  2105.                 tmpreg=0x003;
  2106.                 break;
  2107.             case ITT0:
  2108.                 tmpreg=0x004;
  2109.                 break;
  2110.             case ITT1:
  2111.                 tmpreg=0x005;
  2112.                 break;
  2113.             case DTT0:
  2114.                 tmpreg=0x006;
  2115.                 break;
  2116.             case DTT1:
  2117.                 tmpreg=0x007;
  2118.                 break;
  2119.             case MMUSR:
  2120.                 tmpreg=0x805;
  2121.                 break;
  2122.             case URP:
  2123.                 tmpreg=0x806;
  2124.                 break;
  2125.             case SRP:
  2126.                 tmpreg=0x807;
  2127.                 break;
  2128. #endif m68040
  2129.             default:
  2130.                 abort();
  2131.             }
  2132.             install_operand(s[1],tmpreg);
  2133.             break;
  2134.  
  2135.         case 'k':
  2136.             tmpreg=get_num(opP->con1,55);
  2137.             install_operand(s[1],tmpreg&0x7f);
  2138.             break;
  2139.  
  2140.         case 'l':
  2141.             tmpreg=opP->reg;
  2142.             if(s[1]=='w') {
  2143.                 if(tmpreg&0x7FF0000)
  2144.                     as_bad("Floating point register in register list");
  2145.                 insop(reverse_16_bits(tmpreg));
  2146.             } else {
  2147.                 if(tmpreg&0x700FFFF)
  2148.                     as_bad("Wrong register in floating-point reglist");
  2149.                 install_operand(s[1],reverse_8_bits(tmpreg>>16));
  2150.             }
  2151.             break;
  2152.  
  2153.         case 'L':
  2154.             tmpreg=opP->reg;
  2155.             if(s[1]=='w') {
  2156.                 if(tmpreg&0x7FF0000)
  2157.                     as_bad("Floating point register in register list");
  2158.                 insop(tmpreg);
  2159.             } else if(s[1]=='8') {
  2160.                 if(tmpreg&0x0FFFFFF)
  2161.                     as_bad("incorrect register in reglist");
  2162.                 install_operand(s[1],tmpreg>>24);
  2163.             } else {
  2164.                 if(tmpreg&0x700FFFF)
  2165.                     as_bad("wrong register in floating-point reglist");
  2166.                 else
  2167.                     install_operand(s[1],tmpreg>>16);
  2168.             }
  2169.             break;
  2170.  
  2171.         case 'M':
  2172.             install_operand(s[1],get_num(opP->con1,60));
  2173.             break;
  2174.  
  2175.         case 'O':
  2176.             tmpreg= (opP->mode==DREG)
  2177.                 ? 0x20+opP->reg-DATA
  2178.                 : (get_num(opP->con1,40)&0x1F);
  2179.             install_operand(s[1],tmpreg);
  2180.             break;
  2181.  
  2182.         case 'Q':
  2183.             if (s[1]!='s') {
  2184.                 tmpreg=get_num(opP->con1,10);
  2185.                   if(tmpreg==8)
  2186.                     tmpreg=0;
  2187.             }
  2188.             else {
  2189.                 tmpreg=get_num(opP->con1,20);
  2190.                   if(tmpreg==8)
  2191.                     tmpreg=0;
  2192.             }
  2193.             install_operand(s[1],tmpreg);
  2194.             break;
  2195.  
  2196.         case 'R':
  2197.             /* This depends on the fact that ADDR registers are
  2198.                eight more than their corresponding DATA regs, so
  2199.                the result will have the ADDR_REG bit set */
  2200.             install_operand(s[1],opP->reg-DATA);
  2201.             break;
  2202.  
  2203.         case 's':
  2204.             if(opP->reg==FPI) tmpreg=0x1;
  2205.             else if(opP->reg==FPS) tmpreg=0x2;
  2206.             else if(opP->reg==FPC) tmpreg=0x4;
  2207.             else abort();
  2208.             install_operand(s[1],tmpreg);
  2209.             break;
  2210.  
  2211.         case 'S':    /* Ignore it */
  2212.             break;
  2213.  
  2214.         case 'T':
  2215.             install_operand(s[1],get_num(opP->con1,30));
  2216.             break;
  2217.  
  2218.         case 'U':    /* Ignore it */
  2219.             break;
  2220.  
  2221. #ifdef m68851
  2222.             /* JF: These are out of order, I fear. */
  2223.         case 'f':
  2224.             switch (opP->reg) {
  2225.             case SFC:
  2226.                 tmpreg=0;
  2227.                 break;
  2228.             case DFC:
  2229.                 tmpreg=1;
  2230.                 break;
  2231.             default:
  2232.                 abort();
  2233.             }
  2234.             install_operand(s[1],tmpreg);
  2235.             break;
  2236.  
  2237.         case 'P':
  2238.             switch(opP->reg) {
  2239.             case TC:
  2240.                 tmpreg=0;
  2241.                 break;
  2242.             case CAL:
  2243.                 tmpreg=4;
  2244.                 break;
  2245.             case VAL:
  2246.                 tmpreg=5;
  2247.                 break;
  2248.             case SCC:
  2249.                 tmpreg=6;
  2250.                 break;
  2251.             case AC:
  2252.                 tmpreg=7;
  2253.                 break;
  2254.             default:
  2255.                 abort();
  2256.             }
  2257.             install_operand(s[1],tmpreg);
  2258.             break;
  2259.  
  2260.         case 'V':
  2261.             if (opP->reg == VAL)
  2262.                 break;
  2263.             abort();
  2264.  
  2265.         case 'W':
  2266.             switch(opP->reg) {
  2267.  
  2268.             case DRP:
  2269.                 tmpreg=1;
  2270.                 break;
  2271.             case SRP:
  2272.                 tmpreg=2;
  2273.                 break;
  2274.             case CRP:
  2275.                 tmpreg=3;
  2276.                 break;
  2277.             default:
  2278.                 abort();
  2279.             }
  2280.             install_operand(s[1],tmpreg);
  2281.             break;
  2282.  
  2283.         case 'X':
  2284.             switch (opP->reg) {
  2285.             case BAD: case BAD+1: case BAD+2: case BAD+3:
  2286.             case BAD+4: case BAD+5: case BAD+6: case BAD+7:
  2287.                 tmpreg = (4 << 10) | ((opP->reg - BAD) << 2);
  2288.                 break;
  2289.  
  2290.             case BAC: case BAC+1: case BAC+2: case BAC+3:
  2291.             case BAC+4: case BAC+5: case BAC+6: case BAC+7:
  2292.                 tmpreg = (5 << 10) | ((opP->reg - BAC) << 2);
  2293.                 break;
  2294.  
  2295.             default:
  2296.                 abort();
  2297.             }
  2298.             install_operand(s[1], tmpreg);
  2299.             break;
  2300.         case 'Y':
  2301.             if (opP->reg == PSR)
  2302.                 break;
  2303.             abort();
  2304.  
  2305.         case 'Z':
  2306.             if (opP->reg == PCSR)
  2307.                 break;
  2308.             abort();
  2309. #endif /* m68851 */
  2310.         default:
  2311.             as_fatal("Internal error:  Operand type %c unknown",s[0]);
  2312.         }
  2313.     }
  2314.     /* By the time whe get here (FINALLY) the_ins contains the complete
  2315.        instruction, ready to be emitted. . . */
  2316. }
  2317.  
  2318. int
  2319. get_regs(i,str,opP)
  2320. struct m68k_op *opP;
  2321. char *str;
  2322. {
  2323.     /*                 26, 25, 24, 23-16,  15-8, 0-7 */
  2324.     /* Low order 24 bits encoded fpc,fps,fpi,fp7-fp0,a7-a0,d7-d0 */
  2325.     unsigned long int cur_regs = 0;
  2326.     int    reg1,
  2327.         reg2;
  2328.  
  2329. #define ADD_REG(x)    {     if(x==FPI) cur_regs|=(1<<24);\
  2330.              else if(x==FPS) cur_regs|=(1<<25);\
  2331.              else if(x==FPC) cur_regs|=(1<<26);\
  2332.              else cur_regs|=(1<<(x-1));  }
  2333.  
  2334.     reg1=i;
  2335.     for(;;) {
  2336.         if(*str=='/') {
  2337.             ADD_REG(reg1);
  2338.             str++;
  2339.         } else if(*str=='-') {
  2340.             str++;
  2341.             reg2=m68k_reg_parse(&str);
  2342.             if(reg2<DATA || reg2>=FPREG+8 || reg1==FPI || reg1==FPS || reg1==FPC) {
  2343.                 opP->error="unknown register in register list";
  2344.                 return FAIL;
  2345.             }
  2346.             while(reg1<=reg2) {
  2347.                 ADD_REG(reg1);
  2348.                 reg1++;
  2349.             }
  2350.             if(*str=='\0')
  2351.                 break;
  2352.         } else if(*str=='\0') {
  2353.             ADD_REG(reg1);
  2354.             break;
  2355.         } else {
  2356.             opP->error="unknow character in register list";
  2357.             return FAIL;
  2358.         }
  2359. /* DJA -- Bug Fix.  Did't handle d1-d2/a1 until the following instruction was added */
  2360.         if (*str=='/')
  2361.           str ++;
  2362.         reg1=m68k_reg_parse(&str);
  2363.         if((reg1<DATA || reg1>=FPREG+8) && !(reg1==FPI || reg1==FPS || reg1==FPC)) {
  2364.             opP->error="unknown register in register list";
  2365.             return FAIL;
  2366.         }
  2367.     }
  2368.     opP->reg=cur_regs;
  2369.     return OK;
  2370. }
  2371.  
  2372. int
  2373. reverse_16_bits(in)
  2374. int in;
  2375. {
  2376.     int out=0;
  2377.     int n;
  2378.  
  2379.     static int mask[16] = {
  2380. 0x0001,0x0002,0x0004,0x0008,0x0010,0x0020,0x0040,0x0080,
  2381. 0x0100,0x0200,0x0400,0x0800,0x1000,0x2000,0x4000,0x8000
  2382.     };
  2383.     for(n=0;n<16;n++) {
  2384.         if(in&mask[n])
  2385.             out|=mask[15-n];
  2386.     }
  2387.     return out;
  2388. }
  2389.  
  2390. int
  2391. reverse_8_bits(in)
  2392. int in;
  2393. {
  2394.     int out=0;
  2395.     int n;
  2396.  
  2397.     static int mask[8] = {
  2398. 0x0001,0x0002,0x0004,0x0008,0x0010,0x0020,0x0040,0x0080,
  2399.     };
  2400.  
  2401.     for(n=0;n<8;n++) {
  2402.         if(in&mask[n])
  2403.             out|=mask[7-n];
  2404.     }
  2405.     return out;
  2406. }
  2407.  
  2408. void
  2409. install_operand(mode,val)
  2410. int mode;
  2411. int val;
  2412. {
  2413.     switch(mode) {
  2414.     case 's':
  2415.         the_ins.opcode[0]|=val & 0xFF;    /* JF FF is for M kludge */
  2416.         break;
  2417.     case 'd':
  2418.         the_ins.opcode[0]|=val<<9;
  2419.         break;
  2420.     case '1':
  2421.         the_ins.opcode[1]|=val<<12;
  2422.         break;
  2423.     case '2':
  2424.         the_ins.opcode[1]|=val<<6;
  2425.         break;
  2426.     case '3':
  2427.         the_ins.opcode[1]|=val;
  2428.         break;
  2429.     case '4':
  2430.         the_ins.opcode[2]|=val<<12;
  2431.         break;
  2432.     case '5':
  2433.         the_ins.opcode[2]|=val<<6;
  2434.         break;
  2435.     case '6':
  2436.             /* DANGER!  This is a hack to force cas2l and cas2w cmds
  2437.                to be three words long! */
  2438.         the_ins.numo++;
  2439.         the_ins.opcode[2]|=val;
  2440.         break;
  2441.     case '7':
  2442.         the_ins.opcode[1]|=val<<7;
  2443.         break;
  2444.     case '8':
  2445.         the_ins.opcode[1]|=val<<10;
  2446.         break;
  2447. #ifdef m68040
  2448.     case '9':
  2449.         the_ins.opcode[0]|=val<<6;
  2450.         break;
  2451. #endif m68040
  2452. #ifdef m68851
  2453.     case '9':
  2454.         the_ins.opcode[1]|=val<<5;
  2455.         break;
  2456. #endif
  2457.  
  2458.     case 't':
  2459.         the_ins.opcode[1]|=(val<<10)|(val<<7);
  2460.         break;
  2461.     case 'D':
  2462.         the_ins.opcode[1]|=(val<<12)|val;
  2463.         break;
  2464.     case 'g':
  2465.         the_ins.opcode[0]|=val=0xff;
  2466.         break;
  2467.     case 'i':
  2468.         the_ins.opcode[0]|=val<<9;
  2469.         break;
  2470.     case 'C':
  2471.         the_ins.opcode[1]|=val;
  2472.         break;
  2473.     case 'j':
  2474.         the_ins.opcode[1]|=val;
  2475.         the_ins.numo++;        /* What a hack */
  2476.         break;
  2477.     case 'k':
  2478.         the_ins.opcode[1]|=val<<4;
  2479.         break;
  2480.     case 'b':
  2481.     case 'w':
  2482.     case 'l':
  2483.         break;
  2484.     case 'c':
  2485.     default:
  2486.         abort();
  2487.     }
  2488. }
  2489.  
  2490. void
  2491. install_gen_operand(mode,val)
  2492. int mode;
  2493. int val;
  2494. {
  2495.     switch(mode) {
  2496.     case 's':
  2497.         the_ins.opcode[0]|=val;
  2498.         break;
  2499.     case 'd':
  2500.             /* This is a kludge!!! */
  2501.         the_ins.opcode[0]|=(val&0x07)<<9|(val&0x38)<<3;
  2502.         break;
  2503.     case 'b':
  2504.     case 'w':
  2505.     case 'l':
  2506.     case 'f':
  2507.     case 'F':
  2508.     case 'x':
  2509.     case 'p':
  2510.         the_ins.opcode[0]|=val;
  2511.         break;
  2512.         /* more stuff goes here */
  2513.     default:
  2514.         abort();
  2515.     }
  2516. }
  2517.  
  2518. char *
  2519. crack_operand(str,opP)
  2520. register char *str;
  2521. register struct m68k_op *opP;
  2522. {
  2523.     register int parens;
  2524.     register int c;
  2525.     register char *beg_str;
  2526.  
  2527. /*
  2528. #ifdef CANON && SUN_ASM_SYNTAX
  2529.     for (; *str != '\0'; str++)
  2530.         if (!(*str == ' ' || *str == '\t'))
  2531.             break;
  2532. #endif CANON && SUN_ASM_SYNTAX
  2533.  */
  2534.     if(!str) {
  2535.         return str;
  2536.     }
  2537.     beg_str=str;
  2538.     for(parens=0;*str && (parens>0 || notend(str));str++) {
  2539.         if(*str=='(') parens++;
  2540.         else if(*str==')') {
  2541.             if(!parens) {        /* ERROR */
  2542.                 opP->error="Extra )";
  2543.                 return str;
  2544.             }
  2545.             --parens;
  2546.         }
  2547.     }
  2548.     if(!*str && parens) {        /* ERROR */
  2549.         opP->error="Missing )";
  2550.         return str;
  2551.     }
  2552.     c= *str;
  2553.     *str='\0';
  2554.     if(m68k_ip_op(beg_str,opP)==FAIL) {
  2555.         *str=c;
  2556.         return str;
  2557.     }
  2558.     *str=c;
  2559.     if(c=='}')
  2560.         c= *++str;        /* JF bitfield hack */
  2561.     if(c) {
  2562.         c= *++str;
  2563.         if(!c)
  2564.             as_bad("Missing operand");
  2565.     }
  2566.     return str;
  2567. }
  2568.  
  2569. /* See the comment up above where the #define notend(... is */
  2570. #if 0
  2571. notend(s)
  2572. char *s;
  2573. {
  2574.     if(*s==',') return 0;
  2575.     if(*s=='{' || *s=='}')
  2576.         return 0;
  2577.     if(*s!=':') return 1;
  2578.         /* This kludge here is for the division cmd, which is a kludge */
  2579.     if(index("aAdD#",s[1])) return 0;
  2580.     return 1;
  2581. }
  2582. #endif
  2583.  
  2584. /* This is the guts of the machine-dependent assembler.  STR points to a
  2585.    machine dependent instruction.  This funciton is supposed to emit
  2586.    the frags/bytes it assembles to.
  2587.  */
  2588. void
  2589. md_assemble(str)
  2590. char *str;
  2591. {
  2592.     char *er;
  2593.     short    *fromP;
  2594.     char    *toP;
  2595.     int    m,n;
  2596.     char    *to_beg_P;
  2597.     int    shorts_this_frag;
  2598.  
  2599.     bzero((char *)(&the_ins),sizeof(the_ins));    /* JF for paranoia sake */
  2600.     m68_ip(str);
  2601.     er=the_ins.error;
  2602.     if(!er) {
  2603.         for(n=the_ins.numargs;n;--n)
  2604.             if(the_ins.operands[n].error) {
  2605.                 er=the_ins.operands[n].error;
  2606.                 break;
  2607.             }
  2608.     }
  2609.     if(er) {
  2610.         as_bad("\"%s\" -- Statement '%s' ignored",er,str);
  2611.         return;
  2612.     }
  2613.  
  2614.     if(the_ins.nfrag==0) {    /* No frag hacking involved; just put it out */
  2615.         toP=frag_more(2*the_ins.numo);
  2616.         fromP= &the_ins.opcode[0];
  2617.         for(m=the_ins.numo;m;--m) {
  2618.             md_number_to_chars(toP,(long)(*fromP),2);
  2619.             toP+=2;
  2620.             fromP++;
  2621.         }
  2622.             /* put out symbol-dependent info */
  2623.         for(m=0;m<the_ins.nrel;m++) {
  2624.             switch(the_ins.reloc[m].wid) {
  2625.             case 'B':
  2626.                 n=1;
  2627.                 break;
  2628.             case 'b':
  2629.                 n=1;
  2630.                 break;
  2631.             case '3':
  2632.                 n=2;
  2633.                 break;
  2634.             case 'w':
  2635.                 n=2;
  2636.                 break;
  2637.             case 'l':
  2638.                 n=4;
  2639.                 break;
  2640.             default:
  2641.                 as_fatal("Don't know how to figure width of %c in md_assemble()",the_ins.reloc[m].wid);
  2642.             }
  2643.  
  2644.             fix_new(frag_now,
  2645.                 (toP-frag_now->fr_literal)-the_ins.numo*2+the_ins.reloc[m].n,
  2646.                 n,
  2647.                 the_ins.reloc[m].add,
  2648.                 the_ins.reloc[m].sub,
  2649.                 the_ins.reloc[m].off,
  2650.                 the_ins.reloc[m].pcrel);
  2651.         }
  2652.         return;
  2653.     }
  2654.  
  2655.         /* There's some frag hacking */
  2656.     for(n=0,fromP= &the_ins.opcode[0];n<the_ins.nfrag;n++) {
  2657.         int wid;
  2658.  
  2659.         if(n==0) wid=2*the_ins.fragb[n].fragoff;
  2660.         else wid=2*(the_ins.numo-the_ins.fragb[n-1].fragoff);
  2661.         toP=frag_more(wid);
  2662.         to_beg_P=toP;
  2663.         shorts_this_frag=0;
  2664.         for(m=wid/2;m;--m) {
  2665.             md_number_to_chars(toP,(long)(*fromP),2);
  2666.             toP+=2;
  2667.             fromP++;
  2668.             shorts_this_frag++;
  2669.         }
  2670.         for(m=0;m<the_ins.nrel;m++) {
  2671.             if((the_ins.reloc[m].n)>= 2*shorts_this_frag /* 2*the_ins.fragb[n].fragoff */) {
  2672.                 the_ins.reloc[m].n-= 2*shorts_this_frag /* 2*the_ins.fragb[n].fragoff */;
  2673.                 break;
  2674.             }
  2675.             wid=the_ins.reloc[m].wid;
  2676.             if(wid==0)
  2677.                 continue;
  2678.             the_ins.reloc[m].wid=0;
  2679.             wid = (wid=='b') ? 1 : (wid=='w') ? 2 : (wid=='l') ? 4 : 4000;
  2680.  
  2681.             fix_new(frag_now,
  2682.                 (toP-frag_now->fr_literal)-the_ins.numo*2+the_ins.reloc[m].n,
  2683.                 wid,
  2684.                 the_ins.reloc[m].add,
  2685.                 the_ins.reloc[m].sub,
  2686.                 the_ins.reloc[m].off,
  2687.                 the_ins.reloc[m].pcrel);
  2688.         }
  2689.         know(the_ins.fragb[n].fadd);
  2690.         (void)frag_var(rs_machine_dependent,10,0,(relax_substateT)(the_ins.fragb[n].fragty),
  2691.  the_ins.fragb[n].fadd,the_ins.fragb[n].foff,to_beg_P);
  2692.     }
  2693.     n=(the_ins.numo-the_ins.fragb[n-1].fragoff);
  2694.     shorts_this_frag=0;
  2695.     if(n) {
  2696.         toP=frag_more(n*sizeof(short));
  2697.         while(n--) {
  2698.             md_number_to_chars(toP,(long)(*fromP),2);
  2699.             toP+=2;
  2700.             fromP++;
  2701.             shorts_this_frag++;
  2702.         }
  2703.     }
  2704.     for(m=0;m<the_ins.nrel;m++) {
  2705.         int wid;
  2706.  
  2707.         wid=the_ins.reloc[m].wid;
  2708.         if(wid==0)
  2709.             continue;
  2710.         the_ins.reloc[m].wid=0;
  2711.         wid = (wid=='b') ? 1 : (wid=='w') ? 2 : (wid=='l') ? 4 : 4000;
  2712.  
  2713.         fix_new(frag_now,
  2714.             (the_ins.reloc[m].n + toP-frag_now->fr_literal)-/* the_ins.numo */ shorts_this_frag*2,
  2715.             wid,
  2716.             the_ins.reloc[m].add,
  2717.             the_ins.reloc[m].sub,
  2718.             the_ins.reloc[m].off,
  2719.             the_ins.reloc[m].pcrel);
  2720.     }
  2721. }
  2722.  
  2723. /* This function is called once, at assembler startup time.  This should
  2724.    set up all the tables, etc that the MD part of the assembler needs
  2725.  */
  2726. void
  2727. md_begin()
  2728. {
  2729. /*
  2730.  * md_begin -- set up hash tables with 68000 instructions.
  2731.  * similar to what the vax assembler does.  ---phr
  2732.  */
  2733.     /* RMS claims the thing to do is take the m68k-opcode.h table, and make
  2734.        a copy of it at runtime, adding in the information we want but isn't
  2735.        there.  I think it'd be better to have an awk script hack the table
  2736.        at compile time.  Or even just xstr the table and use it as-is.  But
  2737.        my lord ghod hath spoken, so we do it this way.  Excuse the ugly var
  2738.        names.  */
  2739.  
  2740.     register struct m68k_opcode *ins;
  2741.     register struct m68_incant *hack,
  2742.         *slak;
  2743.     register char *retval = 0;        /* empty string, or error msg text */
  2744.     register int i;
  2745.     register char c;
  2746.  
  2747.     if ((op_hash = hash_new()) == NULL)
  2748.         as_fatal("Virtual memory exhausted");
  2749.  
  2750.     obstack_begin(&robyn,4000);
  2751.     for (ins = m68k_opcodes; ins < endop; ins++) {
  2752.         hack=slak=(struct m68_incant *)obstack_alloc(&robyn,sizeof(struct m68_incant));
  2753.         do {
  2754.             slak->m_operands=ins->args;
  2755.             slak->m_opnum=strlen(slak->m_operands)/2;
  2756.             slak->m_opcode=ins->opcode;
  2757.                 /* This is kludgey */
  2758.             slak->m_codenum=((ins->match)&0xffffL) ? 2 : 1;
  2759.             if((ins+1)!=endop && !strcmp(ins->name,(ins+1)->name)) {
  2760.                 slak->m_next=(struct m68_incant *)
  2761. obstack_alloc(&robyn,sizeof(struct m68_incant));
  2762.                 ins++;
  2763.             } else
  2764.                 slak->m_next=0;
  2765.             slak=slak->m_next;
  2766.         } while(slak);
  2767.  
  2768.         retval = hash_insert (op_hash, ins->name,(char *)hack);
  2769.             /* Didn't his mommy tell him about null pointers? */
  2770.         if(retval && *retval)
  2771.             as_fatal("Internal Error:  Can't hash %s: %s",ins->name,retval);
  2772.     }
  2773.  
  2774.     for (i = 0; i < sizeof(mklower_table) ; i++)
  2775.         mklower_table[i] = (isupper(c = (char) i)) ? tolower(c) : c;
  2776.  
  2777.     for (i = 0 ; i < sizeof(notend_table) ; i++) {
  2778.         notend_table[i] = 0;
  2779.         alt_notend_table[i] = 0;
  2780.     }
  2781.     notend_table[','] = 1;
  2782.     notend_table['{'] = 1;
  2783.     notend_table['}'] = 1;
  2784.     alt_notend_table['a'] = 1;
  2785.     alt_notend_table['A'] = 1;
  2786.     alt_notend_table['d'] = 1;
  2787.     alt_notend_table['D'] = 1;
  2788.     alt_notend_table['#'] = 1;
  2789.     alt_notend_table['f'] = 1;
  2790.     alt_notend_table['F'] = 1;
  2791. #ifdef REGISTER_PREFIX
  2792.     alt_notend_table[REGISTER_PREFIX] = 1;
  2793. #endif
  2794. }
  2795.  
  2796. #if 0
  2797. #define notend(s) ((*s == ',' || *s == '}' || *s == '{' \
  2798.                    || (*s == ':' && index("aAdD#", s[1]))) \
  2799.                ? 0 : 1)
  2800. #endif
  2801.  
  2802. /* This funciton is called once, before the assembler exits.  It is
  2803.    supposed to do any final cleanup for this part of the assembler.
  2804.  */
  2805. void
  2806. md_end()
  2807. {
  2808. }
  2809.  
  2810. /* Equal to MAX_PRECISION in atof-ieee.c */
  2811. #define MAX_LITTLENUMS 6
  2812.  
  2813. /* Turn a string in input_line_pointer into a floating point constant of type
  2814.    type, and store the appropriate bytes in *litP.  The number of LITTLENUMS
  2815.    emitted is stored in *sizeP .  An error message is returned, or NULL on OK.
  2816.  */
  2817. char *
  2818. md_atof(type,litP,sizeP)
  2819. char type;
  2820. char *litP;
  2821. int *sizeP;
  2822. {
  2823.     int    prec;
  2824.     LITTLENUM_TYPE words[MAX_LITTLENUMS];
  2825.     LITTLENUM_TYPE *wordP;
  2826.     char    *t;
  2827.     char    *atof_ieee();
  2828.  
  2829.     switch(type) {
  2830.     case 'f':
  2831.     case 'F':
  2832.     case 's':
  2833.     case 'S':
  2834.         prec = 2;
  2835.         break;
  2836.  
  2837.     case 'd':
  2838.     case 'D':
  2839.     case 'r':
  2840.     case 'R':
  2841.         prec = 4;
  2842.         break;
  2843.  
  2844.     case 'x':
  2845.     case 'X':
  2846.         prec = 6;
  2847.         break;
  2848.  
  2849.     case 'p':
  2850.     case 'P':
  2851.         prec = 6;
  2852.         break;
  2853.  
  2854.     default:
  2855.         *sizeP=0;
  2856.         return "Bad call to MD_ATOF()";
  2857.     }
  2858.     t=atof_ieee(input_line_pointer,type,words);
  2859.     if(t)
  2860.         input_line_pointer=t;
  2861.  
  2862.     *sizeP=prec * sizeof(LITTLENUM_TYPE);
  2863.     for(wordP=words;prec--;) {
  2864.         md_number_to_chars(litP,(long)(*wordP++),sizeof(LITTLENUM_TYPE));
  2865.         litP+=sizeof(LITTLENUM_TYPE);
  2866.     }
  2867.     return "";    /* Someone should teach Dean about null pointers */
  2868. }
  2869.  
  2870. /* Turn an integer of n bytes (in val) into a stream of bytes appropriate
  2871.    for use in the a.out file, and stores them in the array pointed to by buf.
  2872.    This knows about the endian-ness of the target machine and does
  2873.    THE RIGHT THING, whatever it is.  Possible values for n are 1 (byte)
  2874.    2 (short) and 4 (long)  Floating numbers are put out as a series of
  2875.    LITTLENUMS (shorts, here at least)
  2876.  */
  2877. void
  2878. md_number_to_chars(buf,val,n)
  2879. char    *buf;
  2880. long    val;
  2881. int n;
  2882. {
  2883.     switch(n) {
  2884.     case 1:
  2885.         *buf++=val;
  2886.         break;
  2887.     case 2:
  2888.         *buf++=(val>>8);
  2889.         *buf++=val;
  2890.         break;
  2891.     case 4:
  2892.         *buf++=(val>>24);
  2893.         *buf++=(val>>16);
  2894.         *buf++=(val>>8);
  2895.         *buf++=val;
  2896.         break;
  2897.     default:
  2898.         abort();
  2899.     }
  2900. }
  2901.  
  2902. void
  2903. md_number_to_imm(buf,val,n)
  2904. char *buf;
  2905. long val;
  2906. int n;
  2907. {
  2908.     switch(n) {
  2909.     case 1:
  2910.         *buf++=val;
  2911.         break;
  2912.     case 2:
  2913.         *buf++=(val>>8);
  2914.         *buf++=val;
  2915.         break;
  2916.     case 4:
  2917.         *buf++=(val>>24);
  2918.         *buf++=(val>>16);
  2919.         *buf++=(val>>8);
  2920.         *buf++=val;
  2921.         break;
  2922.     default:
  2923.         abort();
  2924.     }
  2925. }
  2926.  
  2927. void
  2928. md_number_to_disp(buf,val,n)
  2929. char    *buf;
  2930. long    val;
  2931. int n;
  2932. {
  2933.     abort();
  2934. }
  2935.  
  2936. void
  2937. md_number_to_field(buf,val,fix)
  2938. char *buf;
  2939. long val;
  2940. void *fix;
  2941. {
  2942.     abort();
  2943. }
  2944.  
  2945.  
  2946. /* *fragP has been relaxed to its final size, and now needs to have
  2947.    the bytes inside it modified to conform to the new size  There is UGLY
  2948.    MAGIC here. ..
  2949.  */
  2950. void
  2951. md_convert_frag(fragP)
  2952. register fragS *fragP;
  2953. {
  2954.   long disp;
  2955.   long ext;
  2956.  
  2957.   /* Address in gas core of the place to store the displacement.  */
  2958.   register char *buffer_address = fragP -> fr_fix + fragP -> fr_literal;
  2959.   /* Address in object code of the displacement.  */
  2960.   register int object_address = fragP -> fr_fix + fragP -> fr_address;
  2961.  
  2962.   know(fragP->fr_symbol);
  2963.  
  2964.   /* The displacement of the address, from current location.  */
  2965.   disp = (fragP->fr_symbol->sy_value + fragP->fr_offset) - object_address;
  2966.  
  2967.   switch(fragP->fr_subtype) {
  2968.   case TAB(BCC68000,BYTE):
  2969.   case TAB(BRANCH,BYTE):
  2970.     know(issbyte(disp));
  2971.     if(disp==0)
  2972.       as_bad("short branch with zero offset: use :w");
  2973.     fragP->fr_opcode[1]=disp;
  2974.     ext=0;
  2975.     break;
  2976.   case TAB(DBCC,SHORT):
  2977.     know(issword(disp));
  2978.     ext=2;
  2979.     break;
  2980.   case TAB(BCC68000,SHORT):
  2981.   case TAB(BRANCH,SHORT):
  2982.     know(issword(disp));
  2983.     fragP->fr_opcode[1]=0x00;
  2984.     ext=2;
  2985.     break;
  2986.   case TAB(BRANCH,LONG):
  2987.     if(flagseen['m']) {
  2988.       if(fragP->fr_opcode[0]==0x61) {
  2989.     fragP->fr_opcode[0]= 0x4E;
  2990.     fragP->fr_opcode[1]= 0xB9;    /* JBSR with ABSL LONG offset */
  2991.     subseg_change(SEG_TEXT, 0);
  2992.     fix_new(fragP, fragP->fr_fix, 4, fragP->fr_symbol, 0, fragP->fr_offset, 0);
  2993.     fragP->fr_fix+=4;
  2994.     ext=0;
  2995.       } else if(fragP->fr_opcode[0]==0x60) {
  2996.         fragP->fr_opcode[0]= 0x4E;
  2997.         fragP->fr_opcode[1]= 0xF9;      /* JMP  with ABSL LONG offset */
  2998.         subseg_change(SEG_TEXT, 0);
  2999.         fix_new(fragP, fragP->fr_fix, 4, fragP->fr_symbol, 0, fragP->fr_offset,0);
  3000.         fragP->fr_fix+=4;
  3001.         ext=0;
  3002.       }else {
  3003.         as_bad("Long branch offset not supported.");
  3004.       }
  3005.     } else {
  3006.       fragP->fr_opcode[1]=0xff;
  3007.       ext=4;
  3008.     }
  3009.     break;
  3010.   case TAB(BCC68000,LONG):
  3011.     /* only Bcc 68000 instructions can come here */
  3012.         /* change bcc into b!cc/jmp absl long */
  3013.     fragP->fr_opcode[0] ^= 0x01; /* invert bcc */
  3014.         fragP->fr_opcode[1] = 0x6;   /* branch offset = 6 */
  3015.  
  3016.     /* JF: these used to be fr_opcode[2,3], but they may be in a
  3017.        different frag, in which case refering to them is a no-no.
  3018.        Only fr_opcode[0,1] are guaranteed to work. */
  3019.         *buffer_address++ = 0x4e;  /* put in jmp long (0x4ef9) */ 
  3020.         *buffer_address++ = 0xf9;  
  3021.         fragP->fr_fix += 2;         /* account for jmp instruction */
  3022.         subseg_change(SEG_TEXT,0);
  3023.         fix_new(fragP, fragP->fr_fix, 4, fragP->fr_symbol, 0, 
  3024.                      fragP->fr_offset,0);
  3025.         fragP->fr_fix += 4;
  3026.         ext=0;
  3027.     break;
  3028.   case TAB(DBCC,LONG):
  3029.         /* only DBcc 68000 instructions can come here */
  3030.         /* change dbcc into dbcc/jmp absl long */
  3031.     /* JF: these used to be fr_opcode[2-7], but that's wrong */
  3032.         *buffer_address++ = 0x00;  /* branch offset = 4 */
  3033.         *buffer_address++ = 0x04;  
  3034.         *buffer_address++ = 0x60;  /* put in bra pc+6 */ 
  3035.         *buffer_address++ = 0x06;  
  3036.         *buffer_address++ = 0x4e;  /* put in jmp long (0x4ef9) */ 
  3037.         *buffer_address++ = 0xf9;  
  3038.  
  3039.         fragP->fr_fix += 6;         /* account for bra/jmp instructions */
  3040.         subseg_change(SEG_TEXT,0);
  3041.         fix_new(fragP, fragP->fr_fix, 4, fragP->fr_symbol, 0, 
  3042.                      fragP->fr_offset,0);
  3043.         fragP->fr_fix += 4;
  3044.         ext=0;
  3045.     break;
  3046.   case TAB(FBRANCH,SHORT):
  3047.     know((fragP->fr_opcode[1]&0x40)==0);
  3048.     ext=2;
  3049.     break;
  3050.   case TAB(FBRANCH,LONG):
  3051.     fragP->fr_opcode[1]|=0x40;    /* Turn on LONG bit */
  3052.     ext=4;
  3053.     break;
  3054.   case TAB(PCREL,SHORT):
  3055.     ext=2;
  3056.     break;
  3057.   case TAB(PCREL,LONG):
  3058.     /* The thing to do here is force it to ABSOLUTE LONG, since
  3059.        PCREL is really trying to shorten an ABSOLUTE address anyway */
  3060.     /* JF FOO This code has not been tested */
  3061.     subseg_change(SEG_TEXT,0);
  3062.     fix_new(fragP, fragP->fr_fix, 4, fragP->fr_symbol, 0, fragP->fr_offset, 0);
  3063.     if((fragP->fr_opcode[1] & 0x3F) != 0x3A)
  3064.       as_bad("Internal error (long PC-relative operand) for insn 0x%04lx at 0x%lx",
  3065.             fragP->fr_opcode[0],fragP->fr_address);
  3066.     fragP->fr_opcode[1]&= ~0x3F;
  3067.     fragP->fr_opcode[1]|=0x39;    /* Mode 7.1 */
  3068.     fragP->fr_fix+=4;
  3069.     /* md_number_to_chars(buffer_address,
  3070.                (long)(fragP->fr_symbol->sy_value + fragP->fr_offset),
  3071.                4); */
  3072.     ext=0;
  3073.     break;
  3074.   case TAB(PCLEA,SHORT):
  3075.     subseg_change(SEG_TEXT,0);
  3076.     fix_new(fragP,(int)(fragP->fr_fix),2,fragP->fr_symbol,(symbolS *)0,fragP->fr_offset,1);
  3077.     fragP->fr_opcode[1] &= ~0x3F;
  3078.     fragP->fr_opcode[1] |= 0x3A;
  3079.     ext=2;
  3080.     break;
  3081.   case TAB(PCLEA,LONG):
  3082.     subseg_change(SEG_TEXT,0);
  3083.     fix_new(fragP,(int)(fragP->fr_fix)+2,4,fragP->fr_symbol,(symbolS *)0,fragP->fr_offset+2,1);
  3084.     *buffer_address++ = 0x01;
  3085.     *buffer_address++ = 0x70;
  3086.     fragP->fr_fix+=2;
  3087.     /* buffer_address+=2; */
  3088.     ext=4;
  3089.     break;
  3090.  
  3091.   }
  3092.   if(ext) {
  3093.     md_number_to_chars(buffer_address,(long)disp,(int)ext);
  3094.     fragP->fr_fix+=ext;
  3095.   }
  3096. }
  3097.  
  3098. /* Force truly undefined symbols to their maximum size, and generally set up
  3099.    the frag list to be relaxed
  3100.  */
  3101. int
  3102. md_estimate_size_before_relax(fragP,segtype)
  3103. register fragS *fragP;
  3104. int segtype;
  3105. {
  3106.     int    old_fix;
  3107.     register char *buffer_address = fragP -> fr_fix + fragP -> fr_literal;
  3108.  
  3109.     old_fix=fragP->fr_fix;
  3110.  
  3111.     /* handle SZ_UNDEF first, it can be changed to BYTE or SHORT */
  3112.     switch(fragP->fr_subtype) {
  3113.     case TAB(BRANCH,SZ_UNDEF):
  3114.         if((fragP->fr_symbol->sy_type&N_TYPE)==segtype) {
  3115.             fragP->fr_subtype=TAB(TABTYPE(fragP->fr_subtype),BYTE);
  3116.             break;
  3117.         } else if(flagseen['m']) {
  3118.             if(fragP->fr_opcode[0]==0x61) {
  3119.                 if(flagseen['l']) {
  3120.                     fragP->fr_opcode[0]= 0x4E;
  3121.                     fragP->fr_opcode[1]= 0xB8;    /* JBSR with ABSL WORD offset */
  3122.                     subseg_change(SEG_TEXT, 0);
  3123.                     fix_new(fragP, fragP->fr_fix, 2, 
  3124.                         fragP->fr_symbol, 0, fragP->fr_offset, 0);
  3125.                     fragP->fr_fix+=2;
  3126.                 } else {
  3127.                     fragP->fr_opcode[0]= 0x4E;
  3128.                     fragP->fr_opcode[1]= 0xB9;    /* JBSR with ABSL LONG offset */
  3129.                     subseg_change(SEG_TEXT, 0);
  3130.                     fix_new(fragP, fragP->fr_fix, 4, 
  3131.                         fragP->fr_symbol, 0, fragP->fr_offset, 0);
  3132.                     fragP->fr_fix+=4;
  3133.                 }
  3134.                 frag_wane(fragP);
  3135.             } else if(fragP->fr_opcode[0]==0x60) {
  3136.                 if(flagseen['l']) {
  3137.                     fragP->fr_opcode[0]= 0x4E;
  3138.                     fragP->fr_opcode[1]= 0xF8;    /* JMP    with ABSL WORD offset */
  3139.                     subseg_change(SEG_TEXT, 0);
  3140.                     fix_new(fragP, fragP->fr_fix, 2, 
  3141.                         fragP->fr_symbol, 0, fragP->fr_offset, 0);
  3142.                     fragP->fr_fix+=2;
  3143.                 } else {
  3144.                     fragP->fr_opcode[0]= 0x4E;
  3145.                     fragP->fr_opcode[1]= 0xF9;    /* JMP    with ABSL LONG offset */
  3146.                     subseg_change(SEG_TEXT, 0);
  3147.                     fix_new(fragP, fragP->fr_fix, 4, 
  3148.                         fragP->fr_symbol, 0, fragP->fr_offset, 0);
  3149.                     fragP->fr_fix+=4;
  3150.                 }
  3151.                 frag_wane(fragP);
  3152.             } else {
  3153.                 as_warn("Long branch offset to extern symbol not supported.");
  3154.             }
  3155.         } else if(flagseen['l']) {    /* Symbol is still undefined.  Make it simple */
  3156.             fix_new(fragP,(int)(fragP->fr_fix),2,fragP->fr_symbol,
  3157.  (symbolS *)0,fragP->fr_offset + 2,1);
  3158.             fragP->fr_fix+=2;
  3159.             fragP->fr_opcode[1]=0x00;
  3160.             frag_wane(fragP);
  3161.         } else {
  3162.             fix_new(fragP,(int)(fragP->fr_fix),4,fragP->fr_symbol,
  3163.  (symbolS *)0,fragP->fr_offset + 4,1);
  3164.             fragP->fr_fix+=4;
  3165.             fragP->fr_opcode[1]=0xff;
  3166.             frag_wane(fragP);
  3167.             break;
  3168.         }
  3169.         break;
  3170.  
  3171.     case TAB(FBRANCH,SZ_UNDEF):
  3172.         if((fragP->fr_symbol->sy_type&N_TYPE)==segtype || flagseen['l']) {
  3173.             fragP->fr_subtype=TAB(FBRANCH,SHORT);
  3174.             fragP->fr_var+=2;
  3175.         } else {
  3176.             fragP->fr_subtype=TAB(FBRANCH,LONG);
  3177.             fragP->fr_var+=4;
  3178.         }
  3179.         break;
  3180.  
  3181.     case TAB(PCREL,SZ_UNDEF):
  3182.         if((fragP->fr_symbol->sy_type&N_TYPE)==segtype || flagseen['l']) {
  3183.             fragP->fr_subtype=TAB(PCREL,SHORT);
  3184.             fragP->fr_var+=2;
  3185.         } else {
  3186.             fragP->fr_subtype=TAB(PCREL,LONG);
  3187.             fragP->fr_var+=4;
  3188.         }
  3189.         break;
  3190.  
  3191.     case TAB(BCC68000,SZ_UNDEF):
  3192.         if((fragP->fr_symbol->sy_type&N_TYPE)==segtype) {
  3193.             fragP->fr_subtype=TAB(BCC68000,BYTE);
  3194.             break;
  3195.         }
  3196.         /* only Bcc 68000 instructions can come here */
  3197.         /* change bcc into b!cc/jmp absl long */
  3198.         fragP->fr_opcode[0] ^= 0x01; /* invert bcc */
  3199.         if(flagseen['l']) {
  3200.             fragP->fr_opcode[1] = 0x04;   /* branch offset = 6 */
  3201.             /* JF: these were fr_opcode[2,3] */
  3202.             buffer_address[0] = 0x4e;  /* put in jmp long (0x4ef9) */ 
  3203.             buffer_address[1] = 0xf8;
  3204.             fragP->fr_fix += 2;         /* account for jmp instruction */
  3205.             subseg_change(SEG_TEXT,0);
  3206.             fix_new(fragP, fragP->fr_fix, 2, fragP->fr_symbol, 0, 
  3207.                              fragP->fr_offset,0);
  3208.             fragP->fr_fix += 2;
  3209.         } else {
  3210.             fragP->fr_opcode[1] = 0x06;   /* branch offset = 6 */
  3211.             /* JF: these were fr_opcode[2,3] */
  3212.             buffer_address[2] = 0x4e;  /* put in jmp long (0x4ef9) */ 
  3213.             buffer_address[3] = 0xf9;
  3214.             fragP->fr_fix += 2;         /* account for jmp instruction */
  3215.             subseg_change(SEG_TEXT,0);
  3216.             fix_new(fragP, fragP->fr_fix, 4, fragP->fr_symbol, 0, 
  3217.                              fragP->fr_offset,0);
  3218.             fragP->fr_fix += 4;
  3219.         }
  3220.         frag_wane(fragP);
  3221.         break;
  3222.  
  3223.     case TAB(DBCC,SZ_UNDEF):
  3224.         if((fragP->fr_symbol->sy_type&N_TYPE)==segtype) {
  3225.             fragP->fr_subtype=TAB(DBCC,SHORT);
  3226.             fragP->fr_var+=2;
  3227.             break;
  3228.         }
  3229.         /* only DBcc 68000 instructions can come here */
  3230.         /* change dbcc into dbcc/jmp absl long */
  3231.         /* JF: these used to be fr_opcode[2-4], which is wrong. */
  3232.         buffer_address[0] = 0x00;  /* branch offset = 4 */
  3233.         buffer_address[1] = 0x04;  
  3234.         buffer_address[2] = 0x60;  /* put in bra pc + ... */ 
  3235.         if(flagseen['l']) {
  3236.             /* JF: these were fr_opcode[5-7] */
  3237.             buffer_address[3] = 0x04; /* plus 4 */
  3238.             buffer_address[4] = 0x4e;/* Put in Jump Word */
  3239.             buffer_address[5] = 0xf8;
  3240.             fragP->fr_fix += 6;      /* account for bra/jmp instruction */
  3241.             subseg_change(SEG_TEXT,0);
  3242.             fix_new(fragP, fragP->fr_fix, 2, fragP->fr_symbol, 0, 
  3243.                              fragP->fr_offset,0);
  3244.             fragP->fr_fix+=2;
  3245.         } else {
  3246.             /* JF: these were fr_opcode[5-7] */
  3247.             buffer_address[3] = 0x06;  /* Plus 6 */
  3248.             buffer_address[4] = 0x4e;  /* put in jmp long (0x4ef9) */ 
  3249.             buffer_address[5] = 0xf9;  
  3250.             fragP->fr_fix += 6;      /* account for bra/jmp instruction */
  3251.             subseg_change(SEG_TEXT,0);
  3252.             fix_new(fragP, fragP->fr_fix, 4, fragP->fr_symbol, 0, 
  3253.                              fragP->fr_offset,0);
  3254.             fragP->fr_fix += 4;
  3255.         }
  3256.         frag_wane(fragP);
  3257.         break;
  3258.  
  3259.     case TAB(PCLEA,SZ_UNDEF):
  3260.         if((fragP->fr_symbol->sy_type&N_TYPE)==segtype || flagseen['l']) {
  3261.             fragP->fr_subtype=TAB(PCLEA,SHORT);
  3262.             fragP->fr_var+=2;
  3263.         } else {
  3264.             fragP->fr_subtype=TAB(PCLEA,LONG);
  3265.             fragP->fr_var+=6;
  3266.         }
  3267.         break;
  3268.  
  3269.     default:
  3270.         break;
  3271.     }
  3272.  
  3273.     /* now that SZ_UNDEF are taken care of, check others */
  3274.     switch(fragP->fr_subtype) {
  3275.     case TAB(BCC68000,BYTE):
  3276.     case TAB(BRANCH,BYTE):
  3277.             /* We can't do a short jump to the next instruction,
  3278.                so we force word mode.  */
  3279.         if(fragP->fr_symbol && fragP->fr_symbol->sy_value==0 &&
  3280.  fragP->fr_symbol->sy_frag==fragP->fr_next) {
  3281.             fragP->fr_subtype=TAB(TABTYPE(fragP->fr_subtype),SHORT);
  3282.             fragP->fr_var+=2;
  3283.         }
  3284.         break;
  3285.     default:
  3286.         break;
  3287.     }
  3288.     return fragP->fr_var + fragP->fr_fix - old_fix;
  3289. }
  3290.  
  3291. /* the bit-field entries in the relocation_info struct plays hell 
  3292.    with the byte-order problems of cross-assembly.  So as a hack,
  3293.    I added this mach. dependent ri twiddler.  Ugly, but it gets
  3294.    you there. -KWK */
  3295. /* on m68k: first 4 bytes are normal unsigned long, next three bytes
  3296. are symbolnum, most sig. byte first.  Last byte is broken up with
  3297. bit 7 as pcrel, bits 6 & 5 as length, bit 4 as pcrel, and the lower
  3298. nibble as nuthin. (on Sun 3 at least) */
  3299. void
  3300. md_ri_to_chars(ri_p, ri)
  3301.      struct relocation_info *ri_p, ri;
  3302. {
  3303.   unsigned char the_bytes[8];
  3304.  
  3305.   /* this is easy */
  3306.   md_number_to_chars(the_bytes, ri.r_address, sizeof(ri.r_address));
  3307.   /* now the fun stuff */
  3308.   the_bytes[4] = (ri.r_symbolnum >> 16) & 0x0ff;
  3309.   the_bytes[5] = (ri.r_symbolnum >> 8) & 0x0ff;
  3310.   the_bytes[6] = ri.r_symbolnum & 0x0ff;
  3311.   the_bytes[7] = (((ri.r_pcrel << 7)  & 0x80) | ((ri.r_length << 5) & 0x60) | 
  3312.     ((ri.r_extern << 4)  & 0x10)); 
  3313.   /* now put it back where you found it */
  3314.   bcopy (the_bytes, (char *)ri_p, sizeof(struct relocation_info));
  3315. }
  3316.  
  3317. #ifndef WORKING_DOT_WORD
  3318. const int md_short_jump_size = 4;
  3319. const int md_long_jump_size = 6;
  3320.  
  3321. void
  3322. md_create_short_jump(ptr,from_addr,to_addr,frag,to_symbol)
  3323. char    *ptr;
  3324. long    from_addr,
  3325.     to_addr;
  3326. fragS    *frag;
  3327. symbolS    *to_symbol;
  3328. {
  3329.     long offset;
  3330.  
  3331.     offset = to_addr - (from_addr+2);
  3332.  
  3333.     md_number_to_chars(ptr  ,(long)0x6000,2);
  3334.     md_number_to_chars(ptr+2,(long)offset,2);
  3335. }
  3336.  
  3337. void
  3338. md_create_long_jump(ptr,from_addr,to_addr,frag,to_symbol)
  3339. char    *ptr;
  3340. long    from_addr,
  3341.     to_addr;
  3342. fragS    *frag;
  3343. symbolS    *to_symbol;
  3344. {
  3345.     long offset;
  3346.  
  3347.     if(flagseen['m']) {
  3348.         offset=to_addr-to_symbol->sy_value;
  3349.         md_number_to_chars(ptr  ,(long)0x4EF9,2);
  3350.         md_number_to_chars(ptr+2,(long)offset,4);
  3351.         fix_new(frag,(ptr+2)-frag->fr_literal,4,to_symbol,(symbolS *)0,(long int)0,0);
  3352.     } else {
  3353.         offset=to_addr - (from_addr+2);
  3354.         md_number_to_chars(ptr  ,(long)0x60ff,2);
  3355.         md_number_to_chars(ptr+2,(long)offset,4);
  3356.     }
  3357. }
  3358.  
  3359. #endif
  3360. /* Different values of OK tell what its OK to return.  Things that aren't OK are an error (what a shock, no?)
  3361.  
  3362.     0:  Everything is OK
  3363.     10:  Absolute 1:8    only
  3364.     20:  Absolute 0:7    only
  3365.     30:  absolute 0:15    only
  3366.     40:  Absolute 0:31    only
  3367.     50:  absolute 0:127    only
  3368.     55:  absolute -64:63    only
  3369.     60:  absolute -128:127    only
  3370.     70:  absolute 0:4095    only
  3371.     80:  No bignums
  3372.  
  3373. */
  3374. int
  3375. get_num(exp,ok)
  3376. struct m68k_exp *exp;
  3377. int ok;
  3378. {
  3379. #ifdef TEST2
  3380.     long    l = 0;
  3381.  
  3382.     if(!exp->e_beg)
  3383.         return 0;
  3384.     if(*exp->e_beg=='0') {
  3385.         if(exp->e_beg[1]=='x')
  3386.             sscanf(exp->e_beg+2,"%x",&l);
  3387.         else
  3388.             sscanf(exp->e_beg+1,"%O",&l);
  3389.         return l;
  3390.     }
  3391.     return atol(exp->e_beg);
  3392. #else
  3393.     char    *save_in;
  3394.     char    c_save;
  3395.  
  3396.     if(!exp) {
  3397.         /* Can't do anything */
  3398.         return 0;
  3399.     }
  3400.     if(!exp->e_beg || !exp->e_end) {
  3401.         seg(exp)=SEG_ABSOLUTE;
  3402.         adds(exp)=0;
  3403.         subs(exp)=0;
  3404.         offs(exp)= (ok==10) ? 1 : 0;
  3405.         as_warn("Null expression defaults to %ld",offs(exp));
  3406.         return 0;
  3407.     }
  3408.  
  3409.     exp->e_siz=0;
  3410.     if(/* ok!=80 && */exp->e_end[-1]==':' && (exp->e_end-exp->e_beg)>=2) {
  3411.         switch(exp->e_end[0]) {
  3412.         case 's':
  3413.         case 'S':
  3414.         case 'b':
  3415.         case 'B':
  3416.             exp->e_siz=1;
  3417.             break;
  3418.         case 'w':
  3419.         case 'W':
  3420.             exp->e_siz=2;
  3421.             break;
  3422.         case 'l':
  3423.         case 'L':
  3424.             exp->e_siz=3;
  3425.             break;
  3426.         default:
  3427.             as_bad("Unknown size for expression \"%c\"",exp->e_end[0]);
  3428.         }
  3429.         exp->e_end-=2;
  3430.     }
  3431.     c_save=exp->e_end[1];
  3432.     exp->e_end[1]='\0';
  3433.     save_in=input_line_pointer;
  3434.     input_line_pointer=exp->e_beg;
  3435.     switch(expression(&(exp->e_exp))) {
  3436.     case SEG_PASS1:
  3437.         seg(exp)=SEG_ABSOLUTE;
  3438.         adds(exp)=0;
  3439.         subs(exp)=0;
  3440.         offs(exp)= (ok==10) ? 1 : 0;
  3441.         as_warn("Unknown expression: '%s' defaulting to %d",exp->e_beg,offs(exp));
  3442.         break;
  3443.  
  3444.     case SEG_NONE:
  3445.         /* Do the same thing the VAX asm does */
  3446.         seg(exp)=SEG_ABSOLUTE;
  3447.         adds(exp)=0;
  3448.         subs(exp)=0;
  3449.         offs(exp)=0;
  3450.         if(ok==10) {
  3451.             as_warn("expression out of range: defaulting to 1");
  3452.             offs(exp)=1;
  3453.         }
  3454.         break;
  3455.     case SEG_ABSOLUTE:
  3456.         switch(ok) {
  3457. #ifdef m68040
  3458.         case 5:
  3459.             if(offs(exp)<0 || offs(exp)>3)
  3460.                 goto outrange;
  3461.             break;
  3462. #endif m68040
  3463.         case 10:
  3464.             if(offs(exp)<1 || offs(exp)>8) {
  3465.                 as_warn("expression out of range: defaulting to 1");
  3466.                 offs(exp)=1;
  3467.             }
  3468.             break;
  3469.         case 20:
  3470.             if(offs(exp)<0 || offs(exp)>7)
  3471.                 goto outrange;
  3472.             break;
  3473.         case 30:
  3474.             if(offs(exp)<0 || offs(exp)>15)
  3475.                 goto outrange;
  3476.             break;
  3477.         case 40:
  3478.             if(offs(exp)<0 || offs(exp)>32)
  3479.                 goto outrange;
  3480.             break;
  3481.         case 50:
  3482.             if(offs(exp)<0 || offs(exp)>127)
  3483.                 goto outrange;
  3484.             break;
  3485.         case 55:
  3486.             if(offs(exp)<-64 || offs(exp)>63)
  3487.                 goto outrange;
  3488.             break;
  3489.         case 60:
  3490.             if(offs(exp)<-128 || offs(exp)>127)
  3491.                 goto outrange;
  3492.             break;
  3493.         case 70:
  3494.             if(offs(exp)<0 || offs(exp)>4095) {
  3495.             outrange:
  3496.                 as_warn("expression out of range: defaulting to 0");
  3497.                 offs(exp)=0;
  3498.             }
  3499.             break;
  3500.         default:
  3501.             break;
  3502.         }
  3503.         break;
  3504.     case SEG_TEXT:
  3505.     case SEG_DATA:
  3506.     case SEG_BSS:
  3507.     case SEG_UNKNOWN:
  3508.     case SEG_DIFFERENCE:
  3509.         if(ok>=10 && ok<=70) {
  3510.             seg(exp)=SEG_ABSOLUTE;
  3511.             adds(exp)=0;
  3512.             subs(exp)=0;
  3513.             offs(exp)= (ok==10) ? 1 : 0;
  3514.             as_warn("Can't deal with expression \"%s\": defaulting to %ld",exp->e_beg,offs(exp));
  3515.         }
  3516.         break;
  3517.     case SEG_BIG:
  3518.         if(ok==80 && offs(exp)<0) {    /* HACK! Turn it into a long */
  3519.             LITTLENUM_TYPE words[6];
  3520.  
  3521.             gen_to_words(words,2,8L);/* These numbers are magic! */
  3522.             seg(exp)=SEG_ABSOLUTE;
  3523.             adds(exp)=0;
  3524.             subs(exp)=0;
  3525.             offs(exp)=words[1]|(words[0]<<16);
  3526.         } else if(ok!=0) {
  3527.             seg(exp)=SEG_ABSOLUTE;
  3528.             adds(exp)=0;
  3529.             subs(exp)=0;
  3530.             offs(exp)= (ok==10) ? 1 : 0;
  3531.             as_warn("Can't deal with expression \"%s\": defaulting to %ld",exp->e_beg,offs(exp));
  3532.         }
  3533.         break;
  3534.     default:
  3535.         abort();
  3536.     }
  3537.     if(input_line_pointer!=exp->e_end+1)
  3538.         as_bad("Ignoring junk after expression");
  3539.     exp->e_end[1]=c_save;
  3540.     input_line_pointer=save_in;
  3541.     if(exp->e_siz) {
  3542.         switch(exp->e_siz) {
  3543.         case 1:
  3544.             if(!isbyte(offs(exp)))
  3545.                 as_warn("expression doesn't fit in BYTE");
  3546.             break;
  3547.         case 2:
  3548.             if(!isword(offs(exp)))
  3549.                 as_warn("expression doesn't fit in WORD");
  3550.             break;
  3551.         }
  3552.     }
  3553.     return offs(exp);
  3554. #endif
  3555. }
  3556.  
  3557. /* These are the back-ends for the various machine dependent pseudo-ops.  */
  3558. void demand_empty_rest_of_line();    /* Hate those extra verbose names */
  3559.  
  3560. void
  3561. s_data1()
  3562. {
  3563.     subseg_new(SEG_DATA,1);
  3564.     demand_empty_rest_of_line();
  3565. }
  3566.  
  3567. void
  3568. s_data2()
  3569. {
  3570.     subseg_new(SEG_DATA,2);
  3571.     demand_empty_rest_of_line();
  3572. }
  3573.  
  3574. void
  3575. s_even()
  3576. {
  3577.     register int temp;
  3578.     register long int temp_fill;
  3579.  
  3580.     temp = 1;        /* JF should be 2? */
  3581.     temp_fill = get_absolute_expression ();
  3582.     if ( ! need_pass_2 ) /* Never make frag if expect extra pass. */
  3583.         frag_align (temp, (int)temp_fill);
  3584.     demand_empty_rest_of_line();
  3585. }
  3586.  
  3587. void
  3588. s_proc()
  3589. {
  3590.     demand_empty_rest_of_line();
  3591. }
  3592.  
  3593. /* s_space is defined in read.c .skip is simply an alias to it. */
  3594.  
  3595. int
  3596. md_parse_option(argP,cntP,vecP)
  3597. char **argP;
  3598. int *cntP;
  3599. char ***vecP;
  3600. {
  3601.     switch(**argP) {
  3602.     case 'l':    /* -l means keep external to 2 bit offset
  3603.                rather than 16 bit one */
  3604.         break;
  3605.  
  3606.     case 'm':
  3607. #ifdef m68040
  3608.         m68k_kind = 0;
  3609. #endif m68040
  3610.         /* Gas almost ignores this option! */
  3611.         (*argP)++;
  3612.         if(**argP=='c')
  3613.             (*argP)++;
  3614.         if(!strcmp(*argP,"68000"))
  3615.             flagseen['m']=2;
  3616.         else if(!strcmp(*argP,"68010")) {
  3617. #ifdef M_SUN
  3618.             omagic= 1<<16|OMAGIC;
  3619. #endif
  3620.             flagseen['m']=1;
  3621.         } else if(!strcmp(*argP,"68020"))
  3622.             flagseen['m']=0;
  3623.         else
  3624. #ifdef m68040
  3625.             if(!strcmp(*argP,"68040")) {
  3626.             flagseen['m']=0;
  3627.             m68k_kind = 4;
  3628.             }
  3629.         else
  3630. #endif m68040
  3631.             as_warn("Unknown -m option ignored");
  3632.         while(**argP)
  3633.             (*argP)++;
  3634.         break;
  3635.  
  3636.     default:
  3637.         return 0;
  3638.     }
  3639.     return 1;
  3640. }
  3641.  
  3642.  
  3643. #ifdef TEST2
  3644.  
  3645. /* TEST2:  Test md_assemble() */
  3646. /* Warning, this routine probably doesn't work anymore */
  3647.  
  3648. main()
  3649. {
  3650.     struct m68_it the_ins;
  3651.     char buf[120];
  3652.     char *cp;
  3653.     int    n;
  3654.  
  3655.     m68_ip_begin();
  3656.     for(;;) {
  3657.         if(!gets(buf) || !*buf)
  3658.             break;
  3659.         if(buf[0]=='|' || buf[1]=='.')
  3660.             continue;
  3661.         for(cp=buf;*cp;cp++)
  3662.             if(*cp=='\t')
  3663.                 *cp=' ';
  3664.         if(is_label(buf))
  3665.             continue;
  3666.         bzero(&the_ins,sizeof(the_ins));
  3667.         m68_ip(&the_ins,buf);
  3668.         if(the_ins.error) {
  3669.             printf("Error %s in %s\n",the_ins.error,buf);
  3670.         } else {
  3671.             printf("Opcode(%d.%s): ",the_ins.numo,the_ins.args);
  3672.             for(n=0;n<the_ins.numo;n++)
  3673.                 printf(" 0x%x",the_ins.opcode[n]&0xffff);
  3674.             printf("    ");
  3675.             print_the_insn(&the_ins.opcode[0],stdout);
  3676.             (void)putchar('\n');
  3677.         }
  3678.         for(n=0;n<strlen(the_ins.args)/2;n++) {
  3679.             if(the_ins.operands[n].error) {
  3680.                 printf("op%d Error %s in %s\n",n,the_ins.operands[n].error,buf);
  3681.                 continue;
  3682.             }
  3683.             printf("mode %d, reg %d, ",the_ins.operands[n].mode,the_ins.operands[n].reg);
  3684.             if(the_ins.operands[n].b_const)
  3685.                 printf("Constant: '%.*s', ",1+the_ins.operands[n].e_const-the_ins.operands[n].b_const,the_ins.operands[n].b_const);
  3686.             printf("ireg %d, isiz %d, imul %d, ",the_ins.operands[n].ireg,the_ins.operands[n].isiz,the_ins.operands[n].imul);
  3687.             if(the_ins.operands[n].b_iadd)
  3688.                 printf("Iadd: '%.*s',",1+the_ins.operands[n].e_iadd-the_ins.operands[n].b_iadd,the_ins.operands[n].b_iadd);
  3689.             (void)putchar('\n');
  3690.         }
  3691.     }
  3692.     m68_ip_end();
  3693.     return 0;
  3694. }
  3695.  
  3696. is_label(str)
  3697. char *str;
  3698. {
  3699.     while(*str==' ')
  3700.         str++;
  3701.     while(*str && *str!=' ')
  3702.         str++;
  3703.     if(str[-1]==':' || str[1]=='=')
  3704.         return 1;
  3705.     return 0;
  3706. }
  3707.  
  3708. #endif
  3709.  
  3710. /* Possible states for relaxation:
  3711.  
  3712. 0 0    branch offset    byte    (bra, etc)
  3713. 0 1            word
  3714. 0 2            long
  3715.  
  3716. 1 0    indexed offsets    byte    a0@(32,d4:w:1) etc
  3717. 1 1            word
  3718. 1 2            long
  3719.  
  3720. 2 0    two-offset index word-word a0@(32,d4)@(45) etc
  3721. 2 1            word-long
  3722. 2 2            long-word
  3723. 2 3            long-long
  3724.  
  3725. */
  3726.  
  3727.  
  3728.  
  3729. #ifdef DONTDEF
  3730. abort()
  3731. {
  3732.     printf("ABORT!\n");
  3733.     exit(12);
  3734. }
  3735.  
  3736. char *index(s,c)
  3737. char *s;
  3738. {
  3739.     while(*s!=c) {
  3740.         if(!*s) return 0;
  3741.         s++;
  3742.     }
  3743.     return s;
  3744. }
  3745.  
  3746. bzero(s,n)
  3747. char *s;
  3748. {
  3749.     while(n--)
  3750.         *s++=0;
  3751. }
  3752.  
  3753. print_frags()
  3754. {
  3755.     fragS *fragP;
  3756.     extern fragS *text_frag_root;
  3757.  
  3758.     for(fragP=text_frag_root;fragP;fragP=fragP->fr_next) {
  3759.         printf("addr %lu  next 0x%x  fix %ld  var %ld  symbol 0x%x  offset %ld\n",
  3760.  fragP->fr_address,fragP->fr_next,fragP->fr_fix,fragP->fr_var,fragP->fr_symbol,fragP->fr_offset);
  3761.         printf("opcode 0x%x  type %d  subtype %d\n\n",fragP->fr_opcode,fragP->fr_type,fragP->fr_subtype);
  3762.     }
  3763.     fflush(stdout);
  3764.     return 0;
  3765. }
  3766. #endif
  3767.  
  3768. #ifdef DONTDEF
  3769. /*VARARGS1*/
  3770. panic(format,args)
  3771. char *format;
  3772. {
  3773.     fputs("Internal error:",stderr);
  3774.     _doprnt(format,&args,stderr);
  3775.     (void)putc('\n',stderr);
  3776.     as_where();
  3777.     abort();
  3778. }
  3779. #endif
  3780.  
  3781. #ifdef m68040
  3782. indirect_fp_inst(name)
  3783. char *name;
  3784. {
  3785.     char **fpinst;
  3786.  
  3787.     for (fpinst = indirect_fp_opcodes; fpinst < endfpinst; fpinst++) {
  3788.         if (!strncmp(name, *fpinst, strlen(*fpinst))
  3789.             && strlen(name) == strlen(*fpinst)+1)
  3790.             return TRUE;
  3791.     }
  3792.     return FALSE;
  3793. }
  3794.  
  3795. m68020_only_inst(name)
  3796. char *name;
  3797. {
  3798.     if (!strcmp(name, "callm") || !strcmp(name, "rtm"))
  3799.         return TRUE;
  3800.     return FALSE;
  3801. }
  3802. #endif m68040
  3803.